django - 否则在 django 中不起作用,我不知道如何解决这个问题
问题描述
Request Method: GET
Request URL: http://127.0.0.1:8000/articles/
Django Version: 2.2.7
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag on line 12: 'else', expected 'endblock'. Did you forget to register or load this tag?
{% extends 'base.html' %}
{% block title %}Ultemele statii{% endblock %}
{% block content %}
{% if latest_articles_list % }
{% for a in latest_articles_list %}
<a href="#">{{a.article_title}}</a>
{% endfor %}
{% else %}
statii ne naidena ))=
{% endif %}
{% endblock %}
代码不起作用
解决方案
您的代码看起来不错,除了if语句中的额外空间:
{% extends 'base.html' %}
{% block title %}Ultemele statii{% endblock %}
{% block content %}
{% if latest_articles_list %}
{% for a in latest_articles_list %}
<a href="#">{{a.article_title}}</a>
{% endfor %}
{% else %}
statii ne naidena ))=
{% endif %}
{% endblock %}
推荐阅读
- c# - 是否需要释放位图局部变量?
- sql - MariaDB 中的组函数错误使用无效 - 更新查询和 SUM
- python-3.x - 如何使用 read_sql 分离数据框中的时间戳数据?
- xml - Ansible - 更新 XML 元素值
- azure - Azure WebJobs Nuget 从版本 3.0-beta 到 3.0。不再找到 BlobTriggerAttribute
- windows-server-2016 - 故障转移 HA 设置但 VM 未迁移?
- sql - 当产品类别中的最后一个产品被删除时,如何编写删除产品类别的触发器?
- pandas - 根据列上的“或”选择 Pandas 中的行
- .htaccess - htaccess 301 将旧 url 重定向到新 url
- atom-editor - Emacs ctrl-u 函数的 Atom 等价物