[Answered ]-Templatetag not working in Django 4.2 template IF condition

1👍

Django templates have a distinction between variable names and template tags, so you can not just use a template tag in an if condition. You need to store it in a helper variable:

<p>{% user_help as uh %}{{ uh }}</p>
{% if uh %}
  <h2>Some help text</h2>
{% endif %}

That being said, I don’t really see why you need a template tag for this, this is equivalent to:

<p>{{ user.needs_help }}</p>
{% if user.needs_help %}
  <h2>Some help text</h2>
{% endif %}

Leave a comment