I want to see if a field/variable is none within a Django template. What is the correct syntax for that?
This is what I currently have:
{% if profile.user.first_name is null %}
<p> -- </p>
{% elif %}
{{ profile.user.first_name }} {{ profile.user.last_name }}
{% endif%}
In the example above, what would I use to replace “null”?
None, False and Trueall are available within template tags and filters.None, False, the empty string ('', "", """""") and empty lists/tuples all evaluate toFalsewhen evaluated byif, so you can easily doA hint: @fabiocerqueira is right, leave logic to models, limit templates to be the only presentation layer and calculate stuff like that in you model. An example: