我是 django&python 的新手。使用 python 3.4.2 和 django 1.8。尝试显示产品列表并遇到错误:
“异常类型:TemplateSyntaxError
异常值:无效的块标签:'endfor'
异常位置:myvirtualenv/lib/python3.4/site-packages/django/template/base.py in invalid_block_tag,第 395 行
无法弄清楚出了什么问题。在 stackoverflow 上发现了一些相关的问题,但它们没有帮助。
请给我一个提示。提前致谢。
意见:
from django.shortcuts import render
from .models import Product
def list_items(request):
products = Product.objects.all()
return render(request, 'catalog/list_item.html', {'products': products})
list_item.html:
<html>
<head>
{% block title %}some title{% endblock %}
</head>
<body>
{% for product in products %)
{{ product }}
{% endfor %}
</body>
</html>
PS 没有内容,{% block title %} 渲染没有错误。