【发布时间】:2023-03-26 00:26:01
【问题描述】:
使用 Nginx+FastCGI 为我的 django 应用程序提供服务时出现以下错误
Invalid block tag: 'add_pinned_status', expected 'else' or 'endif'
奇怪的是,当我使用 Django 开发服务器提供服务时,该站点运行良好。它在大多数情况下也适用于 Nginx,但错误随机出现并随着刷新再次出现。知道可能是什么问题吗?
编辑:这是代码,只是为了澄清没有挂起的 if 语句。
{% extends 'master.html'%}
{% load thumbnail %}
{% load tags %}
{% block 'title' %}
{{ title }}
{% endblock %}
{% block 'content' %}
<div id="feed" class="content">
{% for book in books.object_list %}
<div class="book_preview">
<div class="thumbnail">
<a href="/book/{{ book.id }}/{{ book.get_slug }}/">
{% if book.cover_image %}
{% thumbnail book.cover_image "120" as im %}
<img src="{{ im.url }}" alt="Python for Software Design"/>
{% endthumbnail %}
{% else %}
<img src="{{ STATIC_URL }}default_thumb.jpg" alt="Python for Software Design"/>
{% endif %}
</a>
</div>
<div class="book_details">
<h2 class="book_title">
<a class="book_profile_link" href="/book/{{ book.id }}/{{ book.get_slug }}/">{{ book.title }}</a>
{% if user != book.uploader %}
<a class="shelf_adder {% add_pinned_status request book.pk %}" href="/shelf/{{ book.id }}/toggle/?next={{ request.get_full_path }}" title="Toggle shelf status"></a>
{% endif %}
</h2>
<h3 class="book_subtitle">
{% if book.subtitle %}
{{ book.subtitle }}
{% else %}
<a href='/book/{{book.id}}/edit/#subtitle'>Provide subtitle</a>
{% endif %}
</h3>
<h3 class="book_authors"> by {{ book.author.filter|join:", " }}</h3>
<div class="book_description">
{% if book.description %}
<p>
{{ book.description|truncatewords:25 }}
</p>
{% else %}
<p class="message">No description available. Create one.</p>
{% endif %}
</div>
<div class="book_links">
<a href="/book/{{ book.id }}/{{ book.get_slug }}/" class="book_profile_link" title="Book profile">
Book profile
</a>
<a href="http://{{ book.homepage }}" class="book_website_link" title="Book website" target="_blank">
Book website
</a>
</div>
<p>Points: {{ book.shelf_additions }}</p>
<div class="book_tags">
{% if book.topics.all %}
{% for topic in book.topics.filter %}
<a href="/topic/{{ topic }}/" title="Browse this topic">{{ topic }}</a>
{% endfor %}
{% else %}
<a href="/book/{{ book.id }}/edit/#topics" title='Click to add'>no topics added☹</a>
{% endif %}
</div>
</div>
<div style="clear: both;"></div>
</div>
{% endfor %}
<div class="pagination">
{% if books.has_previous %}
<a href="?page={{ books.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ books.number }} of {{ books.paginator.num_pages }}
</span>
{% if books.has_next %}
<a href="?page={{ books.next_page_number }}">next</a>
{% endif %}
</div>
</div>
{% endblock %}
问题从if user != book.uploader 语句之后的行开始,如您所见,该语句以适当的endif 终止。我怀疑这可能是某种超时,但我不完全确定。请记住,它有时会起作用,但在使用 Nginx 时会随机停止。它与开发服务器完美配合。
【问题讨论】:
标签: django nginx django-templates