I have something like this set up:
我有这样的设置:
class CategoryPage (webapp.RequestHandler):
def get(self):
** DO SOMETHING HERE **
def post(self):
** DO SOMETHING HERE **
** RENDER THE SAME AS get(self)
The question is, after I process the posted data, how would I be able to display the same information as the get(self) function?
问题是,在我处理发布的数据后,我如何能够显示与get(self)函数相同的信息?
5 个解决方案
#1
A redirect, as others suggest, does have some advantage, but it's something of a "heavy" approach. As an alternative, consider refactoring the rendering part into a separate auxiliary method def _Render(self):
and just ending both the get
and post
methods with a call to self.Render()
.
正如其他人所说,重定向确实有一些优势,但这是一种“沉重”的方法。作为替代方案,可以考虑将渲染部分重构为单独的辅助方法def _Render(self):并且只需调用self.Render()就可以结束get和post方法。
#2
Call self.redirect(url) to redirect the user back to the same page over GET. That way, they won't accidentally re-submit the form if they hit refresh.
调用self.redirect(url)将用户重定向回GET上的同一页面。这样,如果表单刷新,他们不会意外地重新提交表单。
#3
That's generally not a good idea as it'll cause confusion. You should really do whatever it is you want to do and then redirect them to the get method.
这通常不是一个好主意,因为它会引起混乱。你应该真正做你想做的事情,然后将它们重定向到get方法。
#4
create_object(request, form_class=FormClass,
post_save_redirect=reverse('-get-url-handler-',
kwargs=dict(key='%(key)s')))
I use the above django shortcut from generic views where you can specify post save redirect , get in your case . There are few more examples in this snippet . Btw, I assumed that you are using django ( helper or patch) with app engine , based on the title of the question. If you are using app engine patch , check out the views.py in "myapp" app sample add_person handler does what you are looking for.
我在通用视图中使用上面的django快捷方式,您可以在其中指定post save redirect,在您的情况下获取。此代码段中还有更多示例。顺便说一句,我假设您正在使用django(帮助器或补丁)与app引擎,基于问题的标题。如果您正在使用应用引擎补丁,请查看“myapp”应用中的views.py示例add_person处理程序执行您要查找的内容。
#5
Actually, your code isn't Django, but webapp (Google's mini-"framework"). Please read the Django documentation: http://docs.djangoproject.com/
实际上,你的代码不是Django,而是webapp(谷歌的迷你“框架”)。请阅读Django文档:http://docs.djangoproject.com/
Django's generic views are only available with app-engine-patch. The helper doesn't support them. You could take a look at the app-engine-patch sample project to learn more about Django on App Engine: http://code.google.com/p/app-engine-patch/
Django的通用视图仅适用于app-engine-patch。助手不支持他们。您可以查看app-engine-patch示例项目,以了解有关App Engine上Django的更多信息:http://code.google.com/p/app-engine-patch/
#1
A redirect, as others suggest, does have some advantage, but it's something of a "heavy" approach. As an alternative, consider refactoring the rendering part into a separate auxiliary method def _Render(self):
and just ending both the get
and post
methods with a call to self.Render()
.
正如其他人所说,重定向确实有一些优势,但这是一种“沉重”的方法。作为替代方案,可以考虑将渲染部分重构为单独的辅助方法def _Render(self):并且只需调用self.Render()就可以结束get和post方法。
#2
Call self.redirect(url) to redirect the user back to the same page over GET. That way, they won't accidentally re-submit the form if they hit refresh.
调用self.redirect(url)将用户重定向回GET上的同一页面。这样,如果表单刷新,他们不会意外地重新提交表单。
#3
That's generally not a good idea as it'll cause confusion. You should really do whatever it is you want to do and then redirect them to the get method.
这通常不是一个好主意,因为它会引起混乱。你应该真正做你想做的事情,然后将它们重定向到get方法。
#4
create_object(request, form_class=FormClass,
post_save_redirect=reverse('-get-url-handler-',
kwargs=dict(key='%(key)s')))
I use the above django shortcut from generic views where you can specify post save redirect , get in your case . There are few more examples in this snippet . Btw, I assumed that you are using django ( helper or patch) with app engine , based on the title of the question. If you are using app engine patch , check out the views.py in "myapp" app sample add_person handler does what you are looking for.
我在通用视图中使用上面的django快捷方式,您可以在其中指定post save redirect,在您的情况下获取。此代码段中还有更多示例。顺便说一句,我假设您正在使用django(帮助器或补丁)与app引擎,基于问题的标题。如果您正在使用应用引擎补丁,请查看“myapp”应用中的views.py示例add_person处理程序执行您要查找的内容。
#5
Actually, your code isn't Django, but webapp (Google's mini-"framework"). Please read the Django documentation: http://docs.djangoproject.com/
实际上,你的代码不是Django,而是webapp(谷歌的迷你“框架”)。请阅读Django文档:http://docs.djangoproject.com/
Django's generic views are only available with app-engine-patch. The helper doesn't support them. You could take a look at the app-engine-patch sample project to learn more about Django on App Engine: http://code.google.com/p/app-engine-patch/
Django的通用视图仅适用于app-engine-patch。助手不支持他们。您可以查看app-engine-patch示例项目,以了解有关App Engine上Django的更多信息:http://code.google.com/p/app-engine-patch/