我的最小项目已经顺利工作了好几天,但刚才突然抛出page not found
错误。
我仔细检查了urls
,但无法找到错误。
请求为http://127.0.0.1:8001/user/login/
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8001/user/login/
Using the URLconf defined in forum.urls, Django tried these URL patterns, in this order:
^admin/
^$ [name='index']
^article/
^user/ ^register$ [name='register']
^user/ ^activate/(?P<a_code>\w+)$ [name='activate']
^user/ ^login$ [name='login']
^user/ ^logout$ [name='logout']
The current path, user/login/, didn't match any of these.
应用user.urls
:
from django.conf.urls import url
from django.contrib.auth import urls
from django.contrib.auth.views import login, logout
from . import views
# User app's url
urlpatterns = [
# show the register page
url(r"^register$", views.register, name="register"),
#activate the user account from the registered email
url(r"^activate/(?P<a_code>\w+)$", views.activate, name="activate"),
# Log in page, override the default registration/login.html
url(r"^login$", login, {"template_name":"user/login.html"},name="login"),
url(r"^logout$", logout, {"template_name":""},name="logout"),
]
顶级urls.py
from django.conf.urls import url,include
from django.contrib import admin
from article import views
# Project url
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r"^$", views.index, name="index"),
url(r'^article/', include('article.urls',namespace='article')),
url(r'^user/', include('user.urls',namespace='user')),
]
模板:
└── user
├── activate.html
├── failure.html
├── login.html
├── register.html
├── success.html
└── validate.html
1 directory, 6 files
问题可能是什么?
答案 0 :(得分:2)
看起来问题与附加的斜杠有关,尝试在模式结束时添加斜杠:
url(r"^login/$", login, {"template_name":"user/login.html"},name="login"),
您也可以在项目设置中停用APPEND_SLASH
。