我刚刚开始我的 Django 之旅,我不知道我做错了什么。抱歉问这个简单的问题。
inz/urls.py
urlpatterns = [
url(r'', include('planner.urls')),
url(r'^admin/', include(admin.site.urls)),]
规划器/urls.py
urlpatterns = [
url(r'^$', views.main_page),
url(r'^/student/$', views.student, name='student'),]
以及我在base.html中的href:
<a href="/student/">Student</a>
我的错误:
Request URL: http://127.0.0.1:8000/student/ Using the URLconf defined in inz.urls, Django tried these URL patterns, in this order: ^$ ^/student/$ [name='student'] ^admin/ The current URL, student/, didn't match any of these.
最佳答案
从 ^/student/$
中删除前导斜杠:
url(r'^student/$', views.student, name='student'),
仅供引用,在 URL 调度程序文档中有一个 related example :
There’s no need to add a leading slash, because every URL has that. For example, it’s
^articles
, not^/articles
.
关于python - 未找到 Django Python 页面 (404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34459254/