Search code examples
pythonhtmldjangodjango-templatesdjango-template-filters

If condition on Django html Template


jobseqno=P567890

<td>
{% if jobseqno|first:"P" %}** <a href="{{ url }}{{ jobseqno }}" target="_blank">{{ jobseqno}}</a>{% endif %}
</td>

The above attached code doesn't work please help me out!!


Solution

  • You can check this with:

    {% if 'P' == jobseqno|first %}
        …
    {%endif %}

    If you are however filtering a QuerySet, you should filter it in the database query, so in the view, not the template.