Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django templates problem — {% if object|length > 4 %} raises TemplateDoesNotExist: 500.html

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>&#9660;</span></a>
                {% endif %}
            </div>
        {% endif %}  
    {% endfor %}
{% endblock %}

And it raises TemplateDoesNotExist: 500.html.

If i write simple {{ fotoList|length }} it works okay.

like image 544
tataata Avatar asked Jan 27 '10 20:01

tataata


People also ask

How do I fix Django TemplateDoesNotExist error?

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.

What does {% %} mean in Django?

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.

Why is {% extends %} tag used?

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.

What {% include %} does?

{% 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.


1 Answers

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 %}
like image 98
Mariusz Jamro Avatar answered Sep 27 '22 21:09

Mariusz Jamro