我有以下Django应用程序结构:
sarpedon33
rango
migrations
sarpedon33
media
static
templates
我收到此评论" App' rango'无法找到。是INSTALLED_APPS吗?"当我尝试为rango应用程序制作时。
settings.py是这样的:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_PATH = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/' # You may find this is already defined as such.
STATICFILES_DIRS = (STATIC_PATH,)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # Absolute path to the media directory
SECRET_KEY = '****************************************************'
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
答案 0 :(得分:4)
将rango
应用添加到INSTALLED_APPS
:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango', # <--- HERE ----
)
答案 1 :(得分:0)
如果有人来到这里是因为他们看到了这个错误,即使他们确实拥有 INSTALLED_APPS中列出的应用,就像我使用旧代码一样。
不要使用project_dir.app_name或任何类似的结构。只写应用程序名称,例如:
错误:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'directory.my_app_name',
)
这是正确的:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'my_app_name',
)