Django:如何重定向到页面,其中的形式来源 [英] Django: How do I redirect to page where form originated

查看:154
本文介绍了Django:如何重定向到页面,其中的形式来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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.


  1. 传递原始页面withi POST / GET

  2. 将会话中的原始页面存储在cookie中(不会显示多个选项卡)

  3. 将原始页面存储在cookie中不能使用多个选项卡)

  4. 如果它是一个页面,重定向到引荐来源。在你的情况下似乎不可能

  1. passing the originating page withi POST/GET
  2. storing the originating page in the session (won't work with multiple tabs obviously)
  3. storing the originating page in a cookie (won't work with multiple tabs either)
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆