1

I have a nested if statement in a template:;

{% if object in request.user.mymodel_set.all %}
    {% if object.pk == request.session.field_pk %}
        Selected
    {% else %}
        <form method="POST" action="myURL" class="">
            {% csrf_token %}
            <input type="submit" value="Select">
        </form>
    {% endif %}
{% endif %}

However the <input> does not render. It does when the parent {% if %} statement is removed. Am I missing something as to how the else statement is handled in this template?

1
  • 1
    Are you sure object in request.user.mymodel_set.all is True? Commented Jan 15, 2020 at 0:56

1 Answer 1

4

Try This

{% if object in request.user.mymodel_set.all %}
   {% if object.pk == request.session.field_pk %}
    Selected
   {% elif object.pk != request.session.field_pk %}
    <form method="POST" action="myURL" class="">
        {% csrf_token %}
        <input type="submit" value="Select">
    </form>
   {% endif %}
{% endif %}

if this is not work too maybe the variables you check in your conditions not True

Sign up to request clarification or add additional context in comments.

1 Comment

please flag as answer to help others find this easly : )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.