You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django访问/notes/路径出现404 Not Found错误求助

Django 404错误:访问/notes/路径找不到页面的解决办法

你的问题核心是路由路径重复嵌套,导致实际匹配的路径和你访问的路径不对应:

  1. 项目根urls.py中已经将/notes/路径分发到Notes应用的路由:
    path('notes/', include('Notes.urls')),
    
  2. 而Notes应用的urls.py里又定义了path('notes/', views.notes_initiator, name='notes'),这就意味着只有访问http://127.0.0.1:8000/notes/notes/才能匹配到视图,你访问的/notes/自然会返回404。

解决步骤

修改Notes\urls.py,把路径中的'notes/'改为空字符串'',让根路由的/notes/直接对应到应用的视图:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.notes_initiator, name='notes'),
]

验证

修改完成后重启Django开发服务器,再次访问http://127.0.0.1:8000/notes/,就能看到预期的"Hello, world. You're at the notes index."消息了。

内容的提问来源于stack exchange,提问作者Noobtocode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 21:27:18