📄 listing26-8.py
字号:
#!/usr/bin/pythonprint 'Content-type: text/html\n'import cgitb; cgitb.enable()def quote(string): if string: return string.replace("'", "\\'") else: return stringimport psycopgconn = psycopg.connect('dbname=foo user=bar')curs = conn.cursor()import cgi, sysform = cgi.FieldStorage()sender = quote(form.getvalue('sender'))subject = quote(form.getvalue('subject'))text = quote(form.getvalue('text'))reply_to = form.getvalue('reply_to')if not (sender and subject and text): print 'Please supply sender, subject, and text' sys.exit()if reply_to is not None: query = """ INSERT INTO messages(reply_to, sender, subject, text) VALUES(%i, '%s', '%s', '%s')""" % (int(reply_to), sender, subject, text)else: query = """ INSERT INTO messages(sender, subject, text) VALUES('%s', '%s', '%s')""" % (sender, subject, text)curs.execute(query)conn.commit()print """<html> <head> <title>Message Saved</title> </head> <body> <h1>Message Saved</h1> <hr /> <a href='main.cgi'>Back to the main page</a> </body></html>s"""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -