Home > Enterprise >  Django logout is not logging out user
Django logout is not logging out user

Time:10-03

I have done a lot of searching and all I can really find are variants of the following:

from django.contrib.auth import logout

def logout_view(request):
    logout(request)
    # Redirect to a success page.

Here is the code from my view:

from django.contrib.auth import logout

def leave(request):
    logout(request)
    return redirect("index")

However, it neither logs the user out nor goes to the index page.

I also have:

path('accounts/', include('django.contrib.auth.urls')),

in my urls page. I tried prefixing my urls with "accounts/" but that just resulted in errors.

CodePudding user response:

in your settings.py add this

LOGOUT_REDIRECT_URL = 'index'

in your template if you want to log out a user just call this (href="{% url 'logout' %}") something like this

<a class="btn btn-primary" href="{% url 'logout' %}"> <span class="glyphicon glyphicon-log-out"></span> log out</a>
  • Related