[Django]-Django template syntax error

5👍

Django tags are surrounded with {% and %} (variables with {{ and }} but let us ignore that for now).

But in your code, except for the first {% if ... %} statement, you consistently write:

{ % endif % }

Notice the space between the { and the %, Django will not parse this as Django tags. You thus should remove the spaces such that the tag reads:

{%  endif  %}

You thus should fix the tags to:

<h2> {{ tag.name|title }} </h2>
 {% if tag.startup_set.all %}
 <section>
 <h3>Startup {{ tag.startup_set.count|pluralize }}</h3>
 <p>
 Tag is associated with
 {{ tag.startup_set.count }}
 startup {{ tag.startup_set.count|pluralize }}
</p>
 <ul>
 {% for startup in tag.startup_set.all %}
 <li><a href="">
 { { startup.name } }
 </a></li>
 {% endfor %}
 </ul>
 </section>
 {% endif %}
 {% if tag.blog_posts.all %}
 <section>
 <h3>Blog Post { { tag.blog_posts.count|pluralize } } </h3>
 <ul>
 {% for post in tag.blog_posts.all %}
 <li><a href="">
 { { post.title|title } }
 </a></li>
 {% endfor %}
 </ul>
 </section>
 {% endif %}
 {% if not tag.startup_set.all and not tag.blog_posts.all %}
 <p>This tag is not related to any content.</p>
 {% endif %}

I would also advice to avoid writing queries (and other business logic) into templates. Usually this is more the task of the view.

Leave a comment