我想发送localhost:8000 / accounts / detail,但无法完成

时间:2017-10-10 03:28:19

标签: python django

我想发送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'),
]

1 个答案:

答案 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]]