Django URLConf:找不到页面错误

时间:2015-02-05 12:31:12

标签: python django url django-views

我在解析网址http://127.0.0.1:8000/userprofile/auth时遇到错误。以下是userprofile应用程序的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

1 个答案:

答案 0 :(得分:2)

您应该将/斜杠添加到action的{​​{1}}属性中:

<form>

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

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

并使用模板中的url(r'^auth/$' , views.auth_view, name='auth_view'), 标记:

{% url %}