Django: How do I redirect to page where form originated

前端 未结 3 1018
情话喂你
情话喂你 2021-02-10 18:27

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 origina

3条回答
  •  醉梦人生
    2021-02-10 19:27

    There are a couple of options, all with the cons and benefits ofcourse.

    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

    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.

提交回复
热议问题