How do I pass template context information when using HttpResponseRedirect in Django?

前端 未结 7 1806
我在风中等你
我在风中等你 2020-12-05 04:26

I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I\'m r

7条回答
  •  失恋的感觉
    2020-12-05 05:06

    The only way I know of to pass any data with a redirect is to add GET parameters to the URL you're passing in. To avoid XSS hacks you'd want to pass a specific constant like:

    [current path you're passing in]?message=saved

    And then process the message=saved parameter in the handler for the path you passed in.

    A somewhat more complicated way would be not passing the data in the redirect, and instead using something like http://code.google.com/p/django-notify/ to store session-based data that is displayed to the user following the redirect.

提交回复
热议问题