gpt4 book ai didi

python - 未找到 Django Python 页面 (404)

转载 作者:行者123 更新时间:2023-11-30 23:02:30 25 4
gpt4 key购买 nike

我刚刚开始我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com