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

前端 未结 7 1805
我在风中等你
我在风中等你 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 04:45

    if you are using auth and have a logged in user you could:

    http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.models.User.message_set.create

    GET params are also hackable. The querystring, as mentioned in other answers, could be used.

    I think the most preferred way would be to use the sessions framework. That way you can load up whatever you want in the context and get

    {{ request.session.foo }} 
    

    foo could be the message or you could do:

    {% ifequal request.session.foo 1 %} Nice work! {% else %} Almost! {% endifequal %}
    

    and other fun stuff.

    http://docs.djangoproject.com/en/dev/topics/http/sessions/#using-sessions-in-views

提交回复
热议问题