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

标签 python html django href django-urls

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

相关文章:

javascript - 我可以让内容出现在 Div 中吗?当光标悬停在单独的 Div 上时?

html - HTML anchor 在距顶部 300px 的绝对 DIV 中有问题..?

Django:计算来自同一模型的行上的字段之间的差异

python - Pip3在哪里安装模块?

python - 想要使用 groupby 和 transform 创建包含唯一值列表的列

python - 为什么用 iTunes 播放器标记的音频文件有 COMMENT :ITUNSMPB and COMMENT:ITUNNORM keys values are not readable format?

python - 本地化数据框中的行

python - RuntimeError : Input type (torch. FloatTensor)和权重类型(torch.cuda.FloatTensor)应该相同

javascript - 类似于 Javascript 中 move_uploaded_file() 的函数

javascript - 在 Django 中使用 JavaScript 的最佳实践