Home > database >  django-allauth or django in general render template on user status
django-allauth or django in general render template on user status

Time:02-02

My menu in the html looks like this:

<ul id="nav-mobile" >
            {% user_display user %}
            <li><a href="/accounts/login">Login</a></li>
            <li><a href="/accounts/logout">Logout</a></li>
            <li><a href="/accounts/signup">Signup</a></li>
</ul>

Obivous this doesn't make much sense, cause if a user is not logged in it should be possible to logout and vice versa.

Are there any template-tags in django or django-allauth, which I can write in the template like. PseudoCode

<if user login>
<a> logout </a>
<end if>

CodePudding user response:

You can simply check if user is logged in with is_authenticated in your template like this:

{% if request.user.is_authenticated %}
     {% user_display user %}
     <li><a href="/accounts/logout">Logout</a></li>
{% else %}
     <li><a href="/accounts/login">Login</a></li>
     <li><a href="/accounts/signup">Signup</a></li>
{% endif %}
  •  Tags:  
  • Related