谷歌应用引擎self.redirect pos

2024-06-26 06:00:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个表单,可以向我的一个处理者发布信息。我的处理程序验证信息,然后需要将此信息发布给第三方,并将用户重定向到该页。

示例

    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()允许发布到第三方站点,但我不认为这是一个选项。

我的目标是在发送给第三方之前检查提供的数据。他们还有别的选择吗?


Tags: theto用户self信息表单ison
1条回答
网友
1楼 · 发布于 2024-06-26 06:00:22

您可以发布表单并将用户重定向到页面,但它们必须是单独的操作。

urlfetch.fetch()方法允许您将方法设置为如下所示:

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)

上面的例子来自URL Fetch Python API Overview

相关问题 更多 >