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

Django无法识别应用URL与视图,持续返回404错误求助

问题分析与解决方案

你的问题出在项目根URL的路由配置上:

你期望访问/home1/hello/,但当前web3/urls.py里把home1应用的URL规则挂载到了根路径(''),这意味着home1/urls.py里的hello/对应的实际访问路径是/hello/,而非你想要的/home1/hello/,所以Django找不到匹配的路由,返回404。

具体修改步骤

修改web3/urls.py,将include('home1.urls')的挂载路径从空字符串改为home1/,同时可以删掉多余的视图导入:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('home1/', include('home1.urls')),  # 关键修改:把''替换为'home1/'
]

验证效果

修改完成后,重启Django开发服务器,访问http://localhost:8000/home1/hello/,就能看到预期的you finally did it justin文本了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 05:33:12