Django:如何重定向到页面,其中的形式来源 [英] Django: How do I redirect to page where form originated
问题描述
在我的Django应用程序中,我有多个页面显示一个链接,加载显示表单的新页面。提交表单时,最简单的方法是重定向到访问此表单的原始页面?
In my Django app I have multiple pages displaying a link that loads a new page displaying a form. When the form is submitted, what is the cleanest way to redirect to the originating page from which this form was accessed?
始发页 - >表单页 - >原始页
使用下一个变量看起来不合理,因为我必须将其设置为源页面链接上的GET变量,然后将其设置为隐藏POST变量在我的窗体?任何其他想法将不胜感激。
Using a next variable seems unellegant since I have to set it as a GET variable on the originating page link, and then set it as a hidden POST variable in my form? Any other ideas would be appreciated.
推荐答案
有两个选项,所有这些都有缺点和益处。 >
There are a couple of options, all with the cons and benefits ofcourse.
- 传递原始页面withi
POST
/GET
- 将会话中的原始页面存储在cookie中(不会显示多个选项卡)
- 将原始页面存储在cookie中不能使用多个选项卡)
- 如果它是一个页面,重定向到引荐来源。在你的情况下似乎不可能
- passing the originating page withi
POST
/GET
- storing the originating page in the session (won't work with multiple tabs obviously)
- storing the originating page in a cookie (won't work with multiple tabs either)
- if it's a single page, redirect to the referrer. Doesn't seem possible in your case
我个人认为使用下一个参数是最好的选择,但请记住保护它只有相对的urls,没有javascript的东西,csrf框架),所以你不会有任何安全问题。
Personally I think using a next parameter is your best option, but do remember to secure it (only relative urls, no javascript stuff, csrf framework) so you won't have any security problems with it.
这篇关于Django:如何重定向到页面,其中的形式来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!