stephan
stephan

Reputation: 2393

Why am I getting an Invalid block tag in my Django template?

I took a short break from Django and I am just returning and I may have forgotten a few things. I tried to put a for loop in my template, and now I'm getting the following error:

Invalid block tag: 'i.headline', expected 'empty' or 'endfor'

I don't know why because I have the endfor tag at the end. I have included my models, views and the html template below (hopefully I have included enough information here).

models.py

class Entry(models.Model):
    headline= models.CharField(max_length=200,)
    body_text = models.TextField()

    def __str__(self):
        return u'%s %s %s %s %s %s %s' % (self.headline, self.body_text)

views.py

def storefront(request):
    latest_entries = Entry.objects.filter()
    context = {'latest_entries': latest_entries}
    return render(request, 'storefront.html', context)

template

 {% for i in latest_entries %}
        <div class="bodydiv">
            <div class="container">
                <div class="grid_4">
                    <div class="imgcontainer">
                        <img src="/static/img/samples/testpic.jpg" alt="" />
                        <div class="overlayname">{% i.headline %}</div>
                    </div>
                    <div class="textcontainer">
                        <p>test test test test test test test teste</p>
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}

Upvotes: 0

Views: 1045

Answers (1)

alecxe
alecxe

Reputation: 473853

Template Variables are surrounded by double-curly braces in Django. Replace:

{% i.headline %}

with:

{{ i.headline }}

{% something %} syntax is used for Template Tags in Django.

Upvotes: 3

Related Questions