![](/img/trans.png)
[英]django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 13: 'endblock'. Did you forget to register or load this tag?
[英]django.template.exceptions.TemplateSyntaxError: Unclosed tag on line 2: 'block'. Looking for one of: endblock. in 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 %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.