Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime error when trying to logout django

When I try to logout from my django project, I get the following error:

"maximum recursion depth exceeded while calling a Python object"

Here is the url for the logout button:

url(r'^logout', 'users.views.logout', name='logout'),

And here is the view:

from django.shortcuts import render
from deck1.models import Card
from django.template import RequestContext 
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import login, authenticate, logout
from django.contrib.auth.decorators import login_required
from users.forms import RegisterForm

@login_required
def logout(request):
    logout(request)
    return  HttpResponseRedirect('/deck')
like image 795
Angel Guastaferro Avatar asked Aug 03 '15 04:08

Angel Guastaferro


1 Answers

Your view logout is overriding the namespace of built-in logout function. Define an alias for django.contrib.auth.login function using as keyword.

from django.contrib.auth import logout as django_logout

@login_required
def logout(request):
    django_logout(request)
    return  HttpResponseRedirect('/deck')
like image 154
Ozgur Vatansever Avatar answered Sep 21 '22 22:09

Ozgur Vatansever