0

我正在学习 django,并从一个小型登录身份验证系统开始。我为登录创建了 html 页面:

<html>
    <title>Login</title>
    <body>
            <br><br><br><br><br><br><br><br><br><br>
            <form name="login" action = "/loginr/" method = "get">
                    USERNAME:<input type="text" name="uname"><br>
                    PASSWORD:<input type="password" name="passwd"><br>
                    <input type = "submit" value = "Login">
            </form>
    </body>
</html>

我的意见.py:

from django.shortcuts import render
from django.http import HttpResponse
def index(request):
    return render(request,'login_page.html')
x=''
def process(request):
    global x
    x=request.GET
    return HttpResponseRedirect('/login/thanks/')
def thanks(request):
    return render(request, 'thanks.html')

我的 urls.py:

from django.conf.urls import patterns,url
from login import views

urlpatterns=patterns('',
            url(r'^$',views.index, name="index"),
            url(r'^loginr/',views.process),
            url(r'^login/thanks/',views.thanks)
    )

最外面的 mysite/urls.py:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^login/', include('login.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^loginr/', include('login.urls')),
url(r'^login/thanks/',include('login.urls')),
)

上面的代码显示没有错误。但是当我填写登录表单并单击登录时,页面本身会重新加载。我想要加载“thanks.html”。我在做什么错?

4

1 回答 1

1

views.py中,您没有导入HttpResponseRedirect.

from django.http import HttpResponseRedirect

更新

更改mysite/urls.py如下:

...
urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('login.urls')),
)

login/urls.py傻:

...
urlpatterns=patterns('',
    url(r'^loginr/?$',views.process),
    url(r'^login/thanks/?$',views.thanks)
    url(r'^login/?$',views.index, name="index"),
)
于 2013-08-03T06:39:11.553 回答