{% extends "./base.html" %}

{% block title %}
        {% if tag %}
        标签页：{{ tag.name }}
        {% elif category %}
        分类页：{{ category.name }}
        {% else %}
        首页
        {% endif %}
{% endblock %}

{% block main %}
    {% for post in post_list %}
             <div class="card post">
              <div class="card-body">
                <h5 class="card-title"><a href="{% url 'post-detail' post.id %} ">{{ post.title }}</a></h5>
                  <span class="card-link">作者：<a href="{% url 'author' post.owner_id %} ">{{ post.owner.username }}</a></span>
                  <span class="card-link">分类：<a href="{% url 'category-list' post.category_id %}">{{ post.category.name }}</a></span>
                  <span class="card-link">标签:
                    {% for tag in post.tag.all %}
                    <a href="{% url 'tag-list' tag.id %}">{{ tag.name }}</a>
                    {% endfor %}
                  </span>
                  <hr/>
                  <p class="card-text">{{ post.desc }}...<a href="{% url 'post-detail' post.id %}">完整内容</a></p>
              </div>
            </div>
    {% endfor %}

    <div>
        {% if page_obj %}
            <nav aria-label="Page navigation example">
             <ul class="pagination">
                {% if page_obj.has_previous %}
                     <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a></li>
                {% else %}
                     <li class="page-item disabled"><a class="page-link" href="#">上一页</a></li>
                {% endif %}

                {% for num in paginator.page_range %}
                   {% if num == page_obj.number %}
                        <li class="page-item active" aria-current="page">
                            <a class="page-link" href="?page={{ num }}">{{ num }}<span class="sr-only">(current)</span></a>
                        </li>
                   {% else %}
                        <li class="page-item"><a class="page-link" href="?page={{ num }}">{{ num }}</a></li>
                   {% endif %}
                {% endfor %}

                {% if page_obj.has_next %}
                   <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a></li>
                {% else %}
                       <li class="page-item disabled"><a class="page-link" href="#">下一页</a></li>
                {% endif %}
              </ul>
              </nav>
        {% endif %}
    </div>


{% endblock %}




