Shuan Wu
Shuan Wu

Reputation: 169

Django Invalid Block Tag: 'endfor'

I wrote these for loop, but I got the Error : Django Invalid Block Tag: 'endfor'

{ % for post in post_list %}
    <div>
    {{ post.title }}
    {{ post.created_at }}
    {{ post.photo }}
    {{ post.content }}
    </div>
{% endfor %}

Upvotes: 5

Views: 4119

Answers (2)

ithecode
ithecode

Reputation: 1

Check the space between the first { and the % sign. It should be {%

Upvotes: 0

xyres
xyres

Reputation: 21744

You're getting that error because there is a space between { and % where the for tag begins.

Change this - { % to look like this - {%, i.e. remove the space between { and %:

{% for post in post_list %}
    ...
{% endfor %}

Upvotes: 5

Related Questions