提前致谢。
我的 Django 网站遇到一个问题。经过身份验证的用户可以在此处访问注册页面。但客户提出了这个问题。因此,我尝试纠正该问题并最终得到以下解决方案。
这是一个好的解决方案吗?或者我怎样才能让它变得好?
流程应该是这样的,当登录用户尝试访问注册页面时,他应该自动从站点注销,然后重定向到注册页面。
我的代码是
def user_signup(request, template_name='profiles/profile_register_form.html'):
if request.user.is_authenticated():
return custom_logout(request, next_page = "/accounts/register/")
def custom_logout(request, next_page='/'):
try:
language = request.session['django_language']
except:
language = False
response = logout(request, next_page=next_page)
if language:
request.session['django_language'] = language
return response
最佳答案
如果我理解你的问题
为什么custom_logout
你可以直接调用 django logout 就像
if request.user.is_authenticated():
logout(request)
return HttpResponseRedirect('/login/') # whatever you register page
关于当用户进入注册页面时,Django 自动注销用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092675/