I have this field on a Django template:
<p class="border_dotted_bottom">
{{ expert.description|slice:":300" }}
<a href="{% url 'profile' expert.username %}">{% trans "read more" %}</a>....
</p>
If this object (user) has no 'decription' (a text field) it shows the word 'None', I need to get rid of that, maybe if he doesn't have a 'description' then show a Simple text and then "read more"
So far, I've tried this:
<p class="border_dotted_bottom">
{{ % if expert.description >= 1 %}}
{{ expert.description|slice:":300" }}
{{% else %}}
Éste usuario por el momento no tiene descripción
<a href="{% url 'profile' expert.username %}">{% trans "read more" %}</a>....
</p>
But it doesn't work, I think it's just a typo, or maybe something to do with the conditional I'm using here...
Anybody can shed some light on this?
Thanks in advance!
Your problem is with your
if/else
tags. You have this:First off, you need to surround
if/else
by{% %}
, not{{% %}}
. Secondly, you don't have anendif
. Anif/else
block should look like this:Therefore, your desired block would look something like this:
That being said, you should be able to simplify this using Django's built-in
default
tag ordefault_if_none
tag, depending on whether you want to give a default ifexpert.description
is equal to''
/None
or onlyNone
: