Django显示段落,如果没有找到

时间:2018-06-25 14:44:49

标签: html django templates if-statement

我希望显示一条消息,如果未找到任何搜索结果,但有人误将其显示!是

  

如果发布在object_list.count == 0

不合适?

我的Django模板:

{% extends 'quickblog/base.html' %}

{% block content %}
    {%  if post in object_list.count == 0 %}
        <p>No results, sorry :(</p>
        {% else %}
    {% for post in object_list %}
        <div class="post">
            <h1><u><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></u></h1>
            <p>{{ post.content|linebreaksbr }}</p>
            <div class="date">
                <a>Published by: {{ post.author }}</a><br>
                <a>Published at: {{ post.published_date }}</a><br>
                <a>Category: {{ post.category }}</a><br>
                <a>Tag(s): {{ post.tag }}</a>
            </div>
        </div>
    {% endfor %}
    {% endif %}

0 个答案:

没有答案