【问题标题】:Python Django Invalid block tag: 'endfor' within a simple templatePython Django 无效块标签:简单模板中的“endfor”
【发布时间】:2015-07-06 13:43:38
【问题描述】:

我是 django&python 的新手。 使用 python 3.4.2 和 django 1.8。 尝试显示产品列表并遇到错误:

"异常类型:TemplateSyntaxError

异常值:无效块标签:'endfor'

异常位置:myvirtualenv/lib/python3.4/site-packages/django/template/base.py 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>

P.S 如果没有内容,{% block title %} 会毫无错误地呈现。

【问题讨论】:

    标签: python django templatetags templatetag


    【解决方案1】:

    你有一个错字:

    {% for product in products %)

    应该是的

    {% for product in products %}

    看括号中的区别}不是)

    【讨论】:

    • 哦。好的..谢谢!
    【解决方案2】:

    您的模板中有语法错误:

    {% for product in products %)
    

    应该是:

    {% for product in products %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      • 2021-10-09
      • 2013-09-01
      • 2018-10-21
      • 2013-06-10
      相关资源
      最近更新 更多