⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listing26-6.py

📁 《Beginning Python--From Novice to Professional》 的源码
💻 PY
字号:
#!/usr/bin/pythonprint 'Content-type: text/html\n'import cgitb; cgitb.enable()import psycopgconn = psycopg.connect('dbname=foo user=bar')curs = conn.cursor()import cgi, sysform = cgi.FieldStorage()id = form.getvalue('id')print """<html>  <head>    <title>View Message</title>  </head>  <body>    <h1>View Message</h1>    """try: id = int(id)except:    print 'Invalid message ID'    sys.exit()curs.execute('SELECT * FROM messages WHERE id = %i' % id)rows = curs.dictfetchall()if not rows:    print 'Unknown message ID'    sys.exit()row = rows[0]print """    <p><b>Subject:</b> %(subject)s<br />    <b>Sender:</b> %(sender)s<br />    <pre>%(text)s</pre>    </p>    <hr />    <a href='main.cgi'>Back to the main page</a>    | <a href="edit.cgi?reply_to=%(id)s">Reply</a>  </body></html>""" % row

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -