假设您要发布一个 html 表单:
<input type="text" name="username">
如果使用raw cgi http://docs.python.org/library/cgi.html:
import cgi
form = cgi.FieldStorage()
print form["username"]
如果使用Django http://docs.djangoproject.com/, Pylons http://pylonshq.com/, Flask http://flask.pocoo.org/ or Pyramid http://www.pylonsproject.org/projects/pyramid/about:
print request.GET['username'] # for GET form method
print request.POST['username'] # for POST form method
Using 涡轮齿轮 http://turbogears.org/, Cherrypy http://www.cherrypy.org/:
from cherrypy import request
print request.params['username']
Web.py http://webpy.org:
form = web.input()
print form.username
Werkzeug http://werkzeug.pocoo.org/:
print request.form['username']
如果使用 Cherrypy 或 Turbogears,您还可以直接使用参数定义处理函数:
def index(self, username):
print username
谷歌应用引擎 https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction:
class SomeHandler(webapp2.RequestHandler):
def post(self):
name = self.request.get('username') # this will get the value from the field named username
self.response.write(name) # this will write on the document
所以你真的必须选择这些框架之一。