简体   繁体   English

Django logout()使Python崩溃

[英]Django logout() crashes Python

I'm having trouble with logout() while testing my project with the Django web server. 使用Django Web服务器测试项目时,我在logout()上遇到了麻烦。 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. 当我访问/ logout(调用此视图)时,出现一个弹出窗口,显示Python崩溃了。 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. logout将自己调用,依此类推,直到堆栈溢出。

Rename the view or the Django logout function when you import it. 导入视图或Django logout函数时,请对其重命名。

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: 例如,如果您使用的是django的登出功能,则将具有以下内容:

from django.contrib.auth import logout as auth_logout

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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