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

Django服务器启动后出现URL匹配错误,请求解决方法

问题分析与解决

从你的代码和描述来看,出现URL匹配错误的原因很明确:你的项目根路径(/)没有对应的URL规则。

你的wiki\urls.py里只配置了两个路径:

  • admin/:对应后台管理页面
  • helo/:映射到helo应用的URL配置

当你启动服务器后直接访问根地址(比如http://localhost:8000/)时,Django遍历wiki\urls.py里的所有规则,找不到能匹配/的项,自然会抛出匹配错误。

解决办法

两种方案选其一即可:

  1. 访问正确的路径:直接访问http://localhost:8000/helo/,就能看到你的Hello响应——这个路径能匹配到helo\urls.py里的空路径规则。
  2. 配置根路径映射:如果想让根地址也显示Hello,修改wiki\urls.py,添加根路径的规则:
from django.contrib import admin
from django.urls import include,path

urlpatterns = [
  path('admin/', admin.site.urls),
  path('helo/', include("helo.urls")),
  path('', include("helo.urls")),  # 新增:把根路径映射到helo的URL配置
]

或者直接把根路径绑定到helo的index视图:

from django.contrib import admin
from django.urls import include,path
from helo.views import index  # 导入视图

urlpatterns = [
  path('admin/', admin.site.urls),
  path('helo/', include("helo.urls")),
  path('', index, name='root_index'),  # 直接绑定根路径到index视图
]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 20:35:17