python - django.template.exceptions.TemplateSyntaxError:第 2 行上的未闭合标签:'block'。寻找其中之一:端块。在 django
问题描述
我正在制作一个 django 应用程序。这是我的index.html
模板:
{% extends "blog/base.html" %}
{% block content %}
{% if latest_post %}
<div class="jumbotron p-4 p-md-5 text-white rounded bg-dark">
<div class="col-md-6 px-0">
<h1 class="display-4 font-italic">
{{ latest_post.title }}
</h1>
<p class="lead my-3">
{{ latest_post.body|truncatewords:30 }}
</p>
<p class="lead mb-0">
<a href="{% url 'blog:post' post.pk %}" class="text-white font-weight-bold">Continue reading...</a>
</p>
</div>
</div>
{% endif %}
{% for post in posts %}
<div class="row mb-2">
<div class="col-md-6">
<div
class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative"
>
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-0">{{ post.title }}</h3>
<div class="mb-1 text-muted">{{ post.date_posted }}</div>
<p class="mb-auto">
{{ post.body|truncatewords:30 }}
</p>
<a href="{% url 'blog:post' post.pk %}" class="stretched-link">Continue reading</a>
{% endfor %}
{% endblock %}
但是,我收到此错误:
django.template.exceptions.TemplateSyntaxError: Unclosed tag on line 2: 'block'. Looking for one of: endblock. in django
我已经确定:
- 所有区块都关闭
- 百分号和块名称之间没有空格
- 我没有错过任何百分号
请帮我
解决方案
在 for 循环中,您<div>
在关闭它们之后有四个打开的元素,看起来没问题。
{% for post in posts %}
<div class="row mb-2">
<div class="col-md-6">
<div class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-0">{{ post.title }}</h3>
<div class="mb-1 text-muted">{{ post.date_posted }}</div>
<p class="mb-auto">
{{ post.body|truncatewords:30 }}
</p>
<a href="{% url 'blog:post' post.pk %}" class="stretched-link">Continue reading</a>
</div></div></div></div>
{% endfor %}
推荐阅读
- python - 随机数列表生成器未按预期工作(Python)
- c++ - 同一线程上的两个连续 memory_order_release 存储可以相互重新排序吗?
- python - 如何从 QLineEdit() 获取 int?
- python - Tensorflow:从任意长度的复杂张量中提取连续补丁
- ios - 具有清晰背景的模态演示在 iPad 上围绕 View 创建 Box - 问题 iOS 13
- node.js - Strapi 覆盖在“database.json”配置文件中设置的数据库环境变量(这是防火墙问题吗?)
- azure-search-.net-sdk - 在 Azure 搜索中显示情绪值
- python - SMTPLIB 是否接收错误?
- arrays - 检查两列以查看一对元素是否都大于单独的最小值?
- r - 函数中的可选过滤器参数过滤或不过滤数据