我有一个表单可以将信息发布给我的一位处理程序。我的处理程序验证信息,然后需要将此信息发布给第三方并将用户重定向到该页面。
的例子
class ExampleHandler(BaseRequestHandler):
"""DocString here...
"""
def post(self):
day = int(self.request.get('day'))
checked_day = CheckDay(day)
if checked_day:
#Here is where I would like to redirect the user to the 3rd party -- but via a post as I will be submitting a form based on data in checked_day on their behalf.
else:
# Otherwise no post redirect is needed -- just a simple self.redirect.
self.redirect('/example')
您对如何将用户重定向到我提交表单的页面有什么建议吗?
理想情况下,我希望有一个 self.redirect() 允许向第三方网站发布帖子,但我不认为这是一个选择。
我的目标是在将数据发送给第三方之前检查所提供的数据。我缺少他们的其他选择吗?
您可以发布表单并将用户重定向到页面,但它们必须是单独的操作。
The urlfetch.fetch()
方法允许您将方法设置为 POST,如下所示:
import urllib
form_fields = {
"first_name": "Albert",
"last_name": "Johnson",
"email_address": "[email protected] /cdn-cgi/l/email-protection"
}
form_data = urllib.urlencode(form_fields)
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
result = urlfetch.fetch(url=url,
payload=form_data,
method=urlfetch.POST,
headers=headers)
上面的例子来自于URL 获取 Python API 概述 http://code.google.com/appengine/docs/python/urlfetch/overview.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)