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

Django执行runserver报错:URLconf无有效路由模式求助

Django URLconf无路由模式错误修复

错误表现

运行python manage.py runserver后,服务器重载时触发以下异常:

django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'base.urls' from 'C:\\Users\\Vignesh\\.vscode\\Interview Dashboard\\dashboard\\base\\urls.py'>' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.

问题根源

检查代码后发现两处致命错误:

  • base.urls.py变量名拼写错误:路由列表的变量名被误写为urspattern,而Django要求必须是urlpatterns,导致框架无法识别路由配置。
  • settings.py应用注册错误:INSTALLED_APPS中注册了不存在的nase.apps.Config,正确的应该是对应你的base应用的配置类。

修复步骤

1. 修正base.urls.py

把错误的变量名改为urlpatterns:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.pplList, name='ppl'),
] 

2. 修正settings.py

更新INSTALLED_APPS,注册正确的base应用:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'base.apps.BaseConfig',  # 替换原错误条目
]

3. 验证与收尾

保存修改后重新启动服务器,错误即可消除。同时记得执行python manage.py migrate处理未完成的数据库迁移。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 02:51:06