Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
If else statement in django template based on request.session data

I'm trying to prevent/allow the user from clicking a button depending on whether a key is present in the request.session data.

It works for blocking it, but once the key is added to the session, that isn't reflected on the webpage/template and the key remains blocked. I presume I'll have to do this in JS but I'm not sure how to approach it. Any ideas?

Thanks

                        {% if choices not in request.session %}
                        <form class="submit-form" action="{% url 'search' %}" method="post" onsubmit="return false;">
                            {% csrf_token %}
                            <input type="submit" class="show-more-button cunt" style="margin-left: 5px" name="mybtn"
                                   value="Search" data-bs-toggle="popover"
                                           data-bs-placement="right" data-bs-trigger="focus"
                                           data-bs-content="Please select one or more ingredient">
                        </form>
                        {% else %}
                        <form action="{% url 'search' %}" method="post">
                            {% csrf_token %}
                            <input type="submit" class="show-more-button" style="margin-left: 5px" name="mybtn"
                                   value="Search">
                        </form>
                        {% endif %}
    if request.POST.get('button_color') == 'green':

        selected_ingredients = request.session.get('choices', [])
        selected_ingredients.insert(len(selected_ingredients), ingredients_name)
        request.session['choices'] = selected_ingredients
        request.session.modified = True
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!