简体   繁体   中英

Django logout() crashes Python

I'm having trouble with logout() while testing my project with the Django web server. This is my logout view:

def logout(request):
    logout(request)
    return render_to_response('main.html', {})

When I access /logout (which calls this view) I get a popup window that says Python crashed. It doesn't give me any trace in the console.

You have a slight problem of recursion there. logout is calling itself, and so on until you get a stack overflow.

Rename the view or the Django logout function when you import it.

The answer above says it all, but I find it helpful to rename external functions with some sort of unique prefix so you know where it's coming from, and because of this prefix, it will never conflict with your own functions. For example, if you're using django's logout function, you would have something like:

from django.contrib.auth import logout as auth_logout

def logout(request):
    auth_logout(request)
    return render_to_response('main.html', {})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM