我想发送localhost:8000/accounts/detail
,但无法完成。
我在views.py中写道
def login(request):
login_form = LoginForm(request.POST)
regist_form = RegisterForm(request.POST)
if regist_form.is_valid():
user = regist_form.save(commit=False)
context = {
'user': request.user,
'login_form': login_form,
'regist_form': regist_form,
}
return HttpResponseRedirect('detail')
if login_form.is_valid():
user = login_form.save(commit=False)
login(request, user)
context = {
'user': request.user,
'login_form': login_form,
'regist_form': regist_form,
}
return HttpResponseRedirect('detail')
context = {
'login_form': login_form,
'regist_form': regist_form,
}
return render(request, 'registration/accounts/login.html', context)
现在在HttpResponseRedirect的部分,它发送localhost:8000/accounts/login/detail
,因此发生错误。此页面读取登录方法为localhost:8000/accounts/login
。我想将网址发送到localhost:8000/accounts/detail
。那么,我该怎么办?解决这个问题?
在urls.py中,我写了
urlpatterns = [
url(r'^detail$', views.detail,name='detail'),
url(r'^login/$', views.login,name='login'),
]
答案 0 :(得分:1)
您必须在 HttpResponseRedirect
中指定确切的网址路径试试这个:
from django.shortcuts import redirect
#codes...
return redirect('detail')
可以从 django.urls
导入反向或者您可以使用:
X[[x for x in range(n_folds) if x != n]]