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

前端 未结 7 1808
我在风中等你
我在风中等你 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:08

    From your views.py you hast have to put a key/value-pair into the session and then read it from the HTML template.

    For example:

    views.py

    # your code here
    request.session['vote'] = 1
    return HttpResponseRedirect(request.path)
    

    your_template.html

    {% ifequal request.session.vote 1 %}
        <!-- Your action here -->
    {% endifequal  %}
    
    0 讨论(0)
提交回复
热议问题