[Answered ]-Show message when there's no excerpt – Django templates

2👍

Your problem is with your if/else tags. You have this:

{{ % if ... %}}
  ...
{{% else %}}
  ...

First off, you need to surround if/else by {% %}, not {{% %}}. Secondly, you don’t have an endif. An if/else block should look like this:

{% if ... %}
  ...
{% else %}
  ...
{% endif %}

Therefore, your desired block would look something like this:

<p class="border_dotted_bottom">
  {% if expert.description >= 1 %}
    {{ expert.description|slice:":300" }}
  {% else %}
    Éste usuario por el momento no tiene descripción
  {% endif %}
  <a href="{% url 'profile' expert.username %}">{% trans "read more" %}</a>....
</p>

That being said, you should be able to simplify this using Django’s built-in default tag or default_if_none tag, depending on whether you want to give a default if expert.description is equal to ''/None or only None:

<p class="border_dotted_bottom">
  {{ expert.description|default:"Éste usuario por el momento no tiene descripción"|slice:":300" }}
  <a href="{% url 'profile' expert.username %}">{% trans "read more" %}</a>....
</p>

Leave a comment