Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Google App Engine重定向并显示错误_Python_Google App Engine - Fatal编程技术网

Python 如何使用Google App Engine重定向并显示错误

Python 如何使用Google App Engine重定向并显示错误,python,google-app-engine,Python,Google App Engine,我正在做一个谷歌应用引擎项目,收集用户提交的故事 以下是我在请求处理程序的post方法中处理提交错误的方式: # get the title and content using self.request.get() errors = [] if not title: errors.append("Please enter a title.") if not content: errors.append("Please enter a story.") if not errors:

我正在做一个谷歌应用引擎项目,收集用户提交的故事

以下是我在请求处理程序的post方法中处理提交错误的方式:

# get the title and content using self.request.get()
errors = []
if not title:
    errors.append("Please enter a title.")
if not content:
    errors.append("Please enter a story.")
if not errors:
    # create the story, save it to the database
    # redirect to the story's page
else:
    # pass the title and/or content to a template
    # pass the error message(s) to a template
    # the same template that displays the submission form is used here
问题是:由于我的表单将帖子发送到example.com/createstory.do——如果有错误,我最终会在该地址重新显示表单页面

我希望发生的事情:将用户重定向回他们提交表单的页面:example.com/Share,同时显示错误消息并重新显示提交的表单数据

最简单的方法是什么


我知道我可以让/Share同时处理get和post请求,但我正在寻找一个解决方案,即使在这样做时我也可以使用它

如果绝对确定需要使用单独的URL,可以重定向到/Share,包括URL中GET变量中的错误。当然,这会让你的URL很难看,因为它现在包含了所有的错误信息

另一种选择是重定向回共享,并将错误存储在cookie或会话变量中


在提交之前,将这两种方法中的任何一种与Javascript中的客户端表单验证结合起来,这样在大多数情况下都不会碰到丑陋的解决方案,这可能是最好的选择。

没有“干净”的方法来做到这一点,因为您无法重定向POST请求(并且让重定向的请求也生成POST)。标准且最干净的方法是,当使用GET获取时,让相同的URL显示表单,并在使用POST获取时接受数据。

可以使用类似urllib的方式请求页面并设置标题吗?文件: