当用户登录时,我试图在导航栏中显示某些内容,但是 {% if user.is_authenticated %}
将其添加到html时不起作用
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">
{% if request.user.is_authenticated %}
<li class="nav-item active">
<a class="nav-item nav-link" id="home" href="/home">Home</a>
</li>
<li class="nav-item active">
<a class="nav-item nav-link" id="logOut" href="/logout">Log-out</a>
</li>
{% else %}
<li class="nav-item active">
<a class="nav-item nav-link" id="login" href="/login">Login</a>
</li>
<li class="nav-item active">
<a class="nav-item nav-link" id="signUp" href="/sign-up">Sign-up</a>
</li>
{% endif %}
</ul>
1条答案
按热度按时间2vuwiymt1#
flask登录添加
current_user
变量添加到模板中