好吧,我对 django 还是很陌生,在个人项目中使用它。我收到以下代码的错误:
{% extends "base.html" %}
{% block content %}
<h1>Website News</h1>
<% if news_items|length > 0 %>
{% for post in news_items %}
<h1>{{post.title}}</h1>
{% autoescape off %}
{{post.content}}
{% endautoescape %}
{% endfor %}
{% else %}
<h1>There are no posts currently</h1>
{% endif %}
{% endblock %}
显然它不喜欢我的 if 语句中的 {% else %}。我已经进行了大量搜索并发现了一些类似的问题,但它们的问题都与不正确的嵌套 block 或错误的字符有关。我已经检查了很多文档,除了 django 提示之外,我的代码没有发现任何问题。
有什么想法吗?
请您参考如下方法:
你有
<% if news_items|length > 0 %>
代替:
{% if news_items|length > 0 %}
在您的代码中,这不是正确的模板标签。
