qq_41535676 2019-01-16 16:10 采纳率: 0%
浏览 2957

django创建项目时,urls.py报错:No module named 'index.urls'

django创建音乐网站项目时,urls.py写入代码后,pycharm一直报错: No module named 'index.urls'

用idle运行时候就报错:
Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

创建过程中只修改了urls.py 和setting.py 文件
代码如下:
[b]urls.py[/b]

from django.contrib import admin

from django.urls import path, include

from django.conf.urls import url

from django.views import static

from django.conf import settings

urlpatterns = [

path('admin/', admin.site.urls),
path('', include('index.urls')),
path('ranking.html', include('ranking.urls')),
path('play/', include('play.urls')),
path('comment/', include('comment.urls')),
path('search/', include('search.urls')),
path('user/', include('user.urls')),

]

[b]settings.py[/b]
(部分代码)
INSTALLED_APPS = [

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'index',
'ranking',
'user',
'play',
'search',
'comment',

]

MIDDLEWARE = [

'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 使用中文
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

ROOT_URLCONF = 'music.urls'

TEMPLATES = [

{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        os.path.join(BASE_DIR, 'templates'),
        os.path.join(BASE_DIR, 'index/templates'),
        os.path.join(BASE_DIR, 'ranking/templates'),
        os.path.join(BASE_DIR, 'user/templates'),
        os.path.join(BASE_DIR, 'play/templates'),
        os.path.join(BASE_DIR, 'comment/templates'),
    ],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},

]

WSGI_APPLICATION = 'music.wsgi.application'

DATABASES = {

'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'music_db',
    'USER': 'root',
    'PASSWORD': '1234',
    'HOST': '127.0.0.1',
    'POST': '3306',
}

}

请问这种情况该如何处理呢?求指点

  • 写回答

1条回答 默认 最新

  • qq_41535676 2019-01-17 10:06
    关注

    已解决:在app下添加urls.py就可以了

    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示