[Answered ]-Does indentation matter in django?

1👍

To fix the issue, you can remove the duplicate block definition and move the contents of the if-else statement into a single block definition.

Try this:

{% block name %}
    {% if object.name == '' %}
        {{ object.name }}
    {% else %}
        {{ object.alternate_name }}
    {% endif %}
{% endblock name %}

0👍

You can not make blocks conditional: these are nodes that are directly at the level of {% extends %}. You can move the condition into the block:

{% block name %}
  {% if object.name == '' %}
    {{ object.name}}
  {% else %}
    {{ object.alternate_name}} 
  {% endif %}
{% endblock name %}

that being said, the condition should probably be reversed. You can also probably use {% firstof … %} [Django-doc]:

{% block name %}
    {% firstof object.name object.alternate_name %}
{% endblock name %}

Leave a comment