Django URLConf:找不到页面错误

Django URLConf: page not found error

解析 url http://127.0.0.1:8000/userprofile/auth 时出现错误。下面是我的 urls.py 用户配置文件应用程序文件:

from django.conf.urls import patterns, url
from userprofile import views
urlpatterns = patterns('',
    url(r'^$', views.login),
    url(r'^auth/$' , views.auth_view),
    url(r'^logout/$', views.logout),
    url(r'/loggedin/$', views.loggedin),
    url(r'/invalid/$', views.invalid_login),
)

主要urls.py如下:

from django.conf.urls import patterns, include, url
from userprofile import views
from django.contrib import admin
admin.autodiscover()

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

这里是link浏览器的截图。

您应该将 / 斜线添加到 <form>action 属性中:

<form action="/userprofile/auth/" method="POST">

或者,作为更好的解决方案,将 url 命名为:

url(r'^auth/$' , views.auth_view, name='auth_view'),

并在模板中使用 {% url %} 标签:

<form action="{% url 'auth_view' %}" method="POST">