# TemplateSyntaxError: Invalid block tag

**URL:** <https://forum.djangoproject.com/t/templatesyntaxerror-invalid-block-tag/15654>\
**Category:** Templates & Frontend\
**Created:** [August 28, 2022, 6:44pm UTC](https://forum.djangoproject.com/t/templatesyntaxerror-invalid-block-tag/15654 "2022-08-28T18:44:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amataee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amataee/32/9867_2.png) [@amataee](https://forum.djangoproject.com/u/amataee)\
**Post date:** [August 28, 2022, 6:44pm UTC](https://forum.djangoproject.com/t/templatesyntaxerror-invalid-block-tag/15654/1 "2022-08-28T18:44:50Z")

</div>

I made a template for my Django project but I’m getting a syntax error that I don’t know where it comes

Here is the error:  
Invalid block tag on line 14: ‘endfor’, expected ‘endblock’. Did you forget to register or load this tag?

And here is my template code:

```auto
{% extends "base.html" %} {% block page_content %}
<div class="col-md-8 offset-md-2">
   <h1>Blog Index</h1>
   <hr />
   {% for post in posts %}
   <h2><a href="{% url 'blog_detail' post.pk%}">{{ post.title }}</a></h2>
   <small>
      {{ post.created_on.date }} |&nbsp; Categories:&nbsp; {% for category in
      post.categories.all %}
      <a href="{% url 'blog_category' category.name %}"> {{ category.name }} </a
      >&nbsp; {% endfor %}
   </small>
   <p>{{ post.body | slice:":400" }}...</p>
   {% endfor %}
</div>
{% endblock %}

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 28, 2022, 6:54pm UTC](https://forum.djangoproject.com/t/templatesyntaxerror-invalid-block-tag/15654/2 "2022-08-28T18:54:24Z")

</div>

If this is an accurate representation of the template, then you’ve got a couple of likely issues here.

First, you’re missing the space in `post.pk%}`.

Second, you’ve got the `{% for category ...` tag split across lines.

The template rendering engine is _extremely_ picky when it comes to syntax of tags, filters, etc. Spaces and linefeeds are critical.

In particular, see [#8652 (Multiline tags and tag escape tags) – Django](https://code.djangoproject.com/ticket/8652).
