Home > OS >  How do I create if statement on django template?
How do I create if statement on django template?

Time:09-16

enter image description here

If there are not projects created, projects is the name of my viewclass for my model, then I need it to create a message, but I do not know how to create the right if statement.

CodePudding user response:

Standard way to implement any if statement in Django's template:

{% if my_projects %}
    Do what you want if condition is ok
{% else %}
    Do what you want if condition is not satisfied
{% endif %}

I assume that my_projects variable contains a list/queryset of projects if any and is passed to the view's context.

  • Related