'Django 4. Invalid block tag on line 45: 'item.title', expected 'empty' or 'endfor'. Did you forget to register or load this tag? [duplicate]
I work on Django 4 I am trying to create a view that will load a template view in django and I am getting the above error.
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 4.0.2
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag on line 45: 'item.title', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
Exception Location: C:\Users\zinnurov.ramil\PycharmProjects\django_full_guide\venv\lib\site-packages\django\template\base.py, line 552, in invalid_block_tag
Python Executable: C:\Users\zinnurov.ramil\PycharmProjects\django_full_guide\venv\Scripts\python.exe
Python Version: 3.9.4
views.py
def index(request):
template_name = 'news/index.html'
news = News.objects.order_by('-created_at')
categories = Category.objects.all()
context = {
'title': 'Список новостей',
'news': news,
'categories': categories,
}
return render(request, template_name, context)
model.py
class Category(models.Model):
title = models.CharField(max_length=200, db_index=True,
verbose_name='Категории')
class Meta:
verbose_name = 'Категория'
verbose_name_plural = 'Категории'
ordering = ['-title']
def __str__(self):
return self.title
<div class="col-md-4">
<div class="list-group">
{% for cat in categories %}
{% item.title %}
{% endfor %}
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
