【发布时间】:2020-08-19 22:12:48
【问题描述】:
<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 %}
【问题讨论】:
-
只将代码放在主页上。
-
您可以在主页视图中将
show_button添加到context字典中,然后在模板中执行{% if show_button %}Button{% endif %}之类的操作。如果您需要更多帮助,请在主页上显示您的视图,并说明您要隐藏哪个按钮。 -
@SergeyPugach 我将我的主页设置为所有其他页面的 base.html,因此它反映在我拥有的每个页面上。
-
你可以有一个 homepage.html 与你的逻辑扩展 base.html
-
@SergeyPugach 是的,可以选择其中之一,谢谢。
标签: django python-3.x django-templates