如何使用 WSGIREF 捕获 POST
我正在尝试从简单的表单中捕获 POST 数据。
这是我第一次使用 WSGIREF,我似乎找不到正确的方法来做到这一点。
This is the form:
<form action="test" method="POST">
<input type="text" name="name">
<input type="submit"></form>
并且该函数显然缺少正确的信息来捕获帖子:
def app(environ, start_response):
"""starts the response for the webserver"""
path = environ[ 'PATH_INFO']
method = environ['REQUEST_METHOD']
if method == 'POST':
if path.startswith('/test'):
start_response('200 OK',[('Content-type', 'text/html')])
return "POST info would go here %s" % post_info
else:
start_response('200 OK', [('Content-type', 'text/html')])
return form()
I am trying to catch POST data from a simple form.
This is the first time I am playing around with WSGIREF and I can't seem to find the correct way to do this.
This is the form:
<form action="test" method="POST">
<input type="text" name="name">
<input type="submit"></form>
And the function that is obviously missing the right information to catch post:
def app(environ, start_response):
"""starts the response for the webserver"""
path = environ[ 'PATH_INFO']
method = environ['REQUEST_METHOD']
if method == 'POST':
if path.startswith('/test'):
start_response('200 OK',[('Content-type', 'text/html')])
return "POST info would go here %s" % post_info
else:
start_response('200 OK', [('Content-type', 'text/html')])
return form()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该读取来自服务器的响应。
来自 nosklo 对类似问题的回答:“PEP 333 说
测试代码(改编自此答案) :
警告:此代码仅用于演示目的。
警告:尽量避免硬编码路径或文件名。
You should be reading responses from the server.
From nosklo's answer to a similar problem: "PEP 333 says you must read environ['wsgi.input']."
Tested code (adapted from this answer):
Caveat: This code is for demonstrative purposes only.
Warning: Try to avoid hard-coding paths or filenames.