我正在尝试将我的Django应用程序部署到DigitalOcean VPS上。我设置了所有内容,当我遇到此错误时即将运行python manage.py collectstatic
:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/demo/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/demo/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/home/demo/.local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/demo/.local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/demo/.local/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named embed_video
问题是我已经使用embed_video
安装了pip install django-embed-video
(Django的this应用程序的应用名称)。我的问题是没有检测到应用程序。
如果它有帮助,我将PostgreSQL实现为生产数据库,将SQLite实现为开发数据库,并且我也使用nginx和gunicorn作为该过程的一部分。
自从有人问起,这是我的settings.py
import os
from os import path
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = False
ALLOWED_HOSTS = []
PROJECT_DIR_PATH = path.dirname(path.normpath(path.abspath(__file__)))
# Application definition
INSTALLED_APPS = [
'about.apps.AboutConfig',
'forms.apps.FormsConfig',
'resources.apps.ResourcesConfig',
'contact.apps.ContactConfig',
'blog.apps.BlogConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'embed_video',
'bootstrap3',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'nydkcd11.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [(os.path.join(BASE_DIR,'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',
'django.template.context_processors.media',
'django.template.context_processors.static',
],
},
},
]
WSGI_APPLICATION = 'nydkcd11.wsgi.application'
#PRODUCTION DATABASE
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'databse', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'myuser',
'PASSWORD': 'password',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = 'media/'
MEDIA_URL = '/media/'
#PRODUCTION
STATIC_ROOT = '/opt/myenv/static/'
STATIC_URL = '/static/'
答案 0 :(得分:1)
您需要检查模块是否在Python中正确安装,您可以先尝试使用pip list
检查以查看python中安装的模块列表。
然后尝试手动导入模块,将其放入控制台:
python
import embed_video
并在embed_video之后单击return时检查是否有任何错误。
你的Pc ???上有更多的Python安装,你使用虚拟环境???,所有这些都可能是你错误的根源。