Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda