#!/usr/bin/python print('Content-type: text/html\n') import cgitb; cgitb.enable() import psycopg2 conn = psycopg2.connect('user=foo password=bar dbname=baz') curs = conn.cursor() import cgi, sys form = cgi.FieldStorage() id = form.getvalue('id') print(""" View Message

View Message

""") try: id = int(id) except: print('Invalid message ID') sys.exit() curs.execute('SELECT * FROM messages WHERE id = %s', (format(id),)) rows = curs.dictfetchall() if not rows: print('Unknown message ID') sys.exit() row = rows[0] print("""

Subject: {subject}
Sender: {sender}

{text}


Back to the main page | Reply """.format(row))