开发者

Django logout() crashes Python

开发者 https://www.devze.com 2023-04-03 12:47 出处:网络
I\'m having trouble with logout() while testing my project with the Django web server.This is my logout view:

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', {})
0

精彩评论

暂无评论...
验证码 换一张
取 消