-1

我是 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 %} 渲染没有错误。

4

2 回答 2

4

你有一个错字:

{% for product in products %)

它应该是

{% for product in products %}

看括号中的差异}不是)

于 2015-07-06T13:46:56.690 回答
2

您的模板中有语法错误:

{% for product in products %)

应该:

{% for product in products %}
于 2015-07-06T13:46:54.390 回答