有没有一种方法可以在除Django网站的主页之外的所有页面上隐藏按钮?

时间:2020-05-05 09:31:34

标签: django python-3.x django-templates

<div class="page-header">
             {% if user.is_authenticated %}
                <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
             {% endif %}
             <h1><a href="/">Django Girls Blog</a></h1>
             {% if user.is_anonymous %}
             <h4><a href="/login">LogIn</a></h4>
             {% endif %}
             {% if user.is_authenticated %}
              <a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
             {% endif %}
             {% if user.is_authenticated %}
             <h3><a href="/user">{{ user }}</a></h3>
             <h4><a href="/logout">LogOut></a></h4>
             {% endif %}

1 个答案:

答案 0 :(得分:0)

绝对。检查当前页面是否为主页,如果不是,则使用css隐藏该按钮。像这样:

<button {% if request.path != '/' %} style="display: none;" {% endif %}>My Button</button>