博客五部曲之二 - 高级博客


1233 浏览 5 years, 3 months

27 面包屑导航

版权声明: 转载请注明出处 http://www.codingsoho.com/

这一节,我们将增加一些导航条能够直接登陆,访问帖子等

在base.html添加下面导航代码

<div class="container">
    <ol class="breadcrumb">
        <li><a href="{% url 'posts:list' %}">Home</a></li>
        {% block post_detail_link %}
        {% endblock %}
        {% if not request.user.is_authenticated %}
        <li class="pull-right"><a href="{% url 'register' %}">Register</a></li>
        <li class="pull-right"><a href="{% url 'login' %}">Login</a></li>
        {% else %}
        <li class="pull-right"><a href="{% url 'logout' %}">Logout</a></li>
        {% endif %}
    </ol>
    {% block content %}
    {% endblock content %}
</div>

对于注册,登陆和注销三个按钮,可以根据当前的登陆状态来显示和关闭。
添加了block post_detail_link,这个在帖子详情页面post_detail.html会实现它,来显示新一级导航

{% block post_detail_link %}
<li><a href="{{instance.get_absolute_url}}">{{instance.title}}</a></li>
{% endblock %}

效果图如下: