Google App Engine self.redirect文章 [英] Google App Engine self.redirect post
问题描述
我有一个表单将信息发布给我的一个处理程序。我的处理程序验证信息,然后需要将这些信息发布给第三方,并将用户重定向到该页面。
的示例
class ExampleHandler(BaseRequestHandler):
DocString here ...
def post(self) :
day = int(self.request.get('day'))
checked_day = CheckDay(day)
如果checked_day:
#这里是我想重定向的地方用户到第三方 - 但通过一个帖子,因为我将代表他们在checked_day基于数据提交表单。
else:
#否则不需要发布重定向 - 只是一个简单的self.redirect。
self.redirect('/ example')
可以将用户重定向到我提交表单的页面?
理想情况下,我希望self.redirect()允许发布到第三方网站,我相信这是一个选项。
我的目标是在将它们发送给第三方之前检查提供的数据。是他们的其他选项我缺少?
您可以张贴表单并将用户重定向到一个页面,但他们会必须是单独的操作。
$ b
urlfetch.fetch()
方法可让您将方法设置为POST : 导入urllib
form_fields = {
first_name:Albert,
last_name:Johnson,
email_address:Albert.Johnson@example.com
}
form_data = urllib.urlencode(form_fields)
header = {'Content-Type':'application / x-www-form-urlencoded'}
result = urlfetch.fetch(url = url,
payload = form_data,
method = urlfetch .POST,
headers = headers)
以上例子来自 URL抓取Python API概述。
I have a form that POSTs information to one of my handlers. My handler verifies the information and then needs to POST this information to a third party AND redirect the user to that page.
Example of the
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')
Do you have any advice on how I can redirect the user to the page where I have submitted a form?
I would ideally like a self.redirect() that allowed POSTs to 3rd party sites but I don't believe this is an option.
My goal is to check the data provided before sending them along to the 3rd party. Are their other options I am missing?
You can POST the form and redirect the user to a page, but they'll have to be separate operations.
The urlfetch.fetch()
method lets you set the method to POST like so:
import urllib
form_fields = {
"first_name": "Albert",
"last_name": "Johnson",
"email_address": "Albert.Johnson@example.com"
}
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)
The above example is from the URL Fetch Python API Overview.
这篇关于Google App Engine self.redirect文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!