我正在创建一个django项目.但是,我遇到了一个小小的打嗝.我的urls.py看起来像这样
url(r'^login/(?P<nextLoc>)$', 'Home.views.login'),
url(r'^logout/$', 'Home.views.logout'),
Run Code Online (Sandbox Code Playgroud)
我在家庭应用程序中的views.py如下:
def login(request,nextLoc):
if request.method == "POST":
form = AuthenticationForm(request.POST)
user=auth.authenticate(username=request.POST['username'],password=request.POST['password'])
if user is not None:
if user.is_active:
auth.login(request, user)
return redirect(nextLoc)
else:
error='This account has been disabled by the administrator. Contact the administrator for enabling the said account'
else:
error='The username/password pair is incorrect. Check your credentials and try again.'
else:
if request.user.is_authenticated():
return redirect("/profile/")
form = AuthenticationForm()
error=''
return render_to_response('login.html',{'FORM':form,'ERROR':error},context_instance=RequestContext(request))
def logout(request):
auth.logout(request)
return redirect('/')
Run Code Online (Sandbox Code Playgroud)
现在,当我进入登录页面时,它正按预期打开.提交表单后,我收到一条错误消息,指出它无法找到模块URL.在挖了一下之后,我注意到重定向("/")实际上转化为http://localhost/login/而不是http://localhost/.注销时也会发生同样的情况,即尝试打开网址http://localhost/logout/而不是http://localhost/ …