I have the following in my template.
{% block content %}
{% for album in albumsList %}
{% if fotosList %}
<div class="photoalbum-wrapper">
<h3>{{ album.title }}</h3>
<ul class="photoalbum">
{% for foto in fotosList %}<li>item</li>{% endfor %}
</ul>
{% if fotosList|length > 4 %}
<a href="#" class="trigger">больше <span>▼</span></a>
{% endif %}
</div>
{% endif %}
{% endfor %}
{% endblock %}
And it raises TemplateDoesNotExist: 500.html.
If i write simple {{ fotoList|length }} it works okay.
Django TemplateDoesNotExist error means simply that the framework can't find the template file. To use the template-loading API, you'll need to tell the framework where you store your templates. The place to do this is in your settings file ( settings.py ) by TEMPLATE_DIRS setting.
This tag can be used in two ways: {% extends "base.html" %} (with quotes) uses the literal value "base.html" as the name of the parent template to extend. {% extends variable %} uses the value of variable . If the variable evaluates to a string, Django will use that string as the name of the parent template.
The extends tag is used to declare a parent template. It should be the very first tag used in a child template and a child template can only extend up to one parent template. To summarize, parent templates define blocks and child templates will override the contents of those blocks.
{% include %} Processes a partial template. Any variables in the parent template will be available in the partial template. Variables set from the partial template using the set or assign tags will be available in the parent template.
This is a very old question. Since then, newer versions of Django support operators in if-statement out of the box, so the following code will work just fine:
{% if fotosList|length > 4 %}
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With