我正在编写一个Django应用程序并在线部署它,但我遇到了静态文件的一些问题。当我运行collectstatic命令时,它会显示“没有名为的模块”。我看过这里的问题,但没有人回答我的问题。
我的静态文件被愚蠢地放入了特定于应用程序的目录中,但我将它们移出并尝试在它们位于正确的目录中时运行它但仍然没有运气。
真的很奇怪:
Settings.py:
"""
Django settings for django_project project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_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',
'ticketr', # App name
)
MIDDLEWARE_CLASSES = (
'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 = 'django_project.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',
],
},
},
]
WSGI_APPLICATION = 'django_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, '../db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATICFILES_DIRS = '/home/django/ticketr/static'
# Tried it at: '/home/django/django_project/django_project/static'
# Also tried it at: '/home/django/static'
STATIC_URL = '/static/'
目录
.
├── db.sqlite3
├── django_project
│ ├── db.sqlite3
│ ├── django_project
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── settings.py
│ │ ├── settings.pyc
│ │ ├── settings.pye
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── wsgi.py
│ │ └── wsgi.pyc
│ └── manage.py
├── images
│ ├── event_images
├── media
│ ├── images
│ └── qrcode
├── qrcode
├── templates
└── ticketr
├── admin.py
├── admin.pyc
├── apps.py
├── forms.py
├── forms.pyc
├── helper.py
├── helper.pyc
├── __init__.py
├── __init__.pyc
├── media
│ └── images
│ └── event_images
├── migrations
├── models.py
├── models.pyc
├── static
│ ├── css
│ │ ├── bootstrap.css
│ │ ├── bootstrap.css.map
│ │ ├── bootstrap.min.css
│ │ ├── bootstrap.min.css.map
│ │ ├── bootstrap-theme.css
│ │ ├── bootstrap-theme.css.map
│ │ ├── bootstrap-theme.min.css
│ │ └── bootstrap-theme.min.css.map
│ ├── fonts
│ │ ├── glyphicons-halflings-regular.eot
│ │ ├── glyphicons-halflings-regular.svg
│ │ ├── glyphicons-halflings-regular.ttf
│ │ ├── glyphicons-halflings-regular.woff
│ │ └── glyphicons-halflings-regular.woff2
│ ├── images
│ │ ├── background1.png
│ │ ├── event_images
│ │ ├── logo.png
│ │ └── qr.jpg
│ └── js
│ └── bootstrap.min.js
├── templatetags
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── ticket_extras.py
│ └── ticket_extras.pyc
├── tests.py
├── urls.py
├── urls.pyc
├── views.py
└── views.pyc
答案 0 :(得分:0)
确保将STATICFILES_FINDERS
设置为default setting in the docs - 即在应用中找到静态文件的内容。您的静态文件位于应用内的/static/
文件夹中,因此您可以删除STATICFILES_DIRS
设置。
您可能还希望每the docs添加STATIC_ROOT
和STATIC_URL
。
编辑:您还有一个奇怪的目录结构。它应该看起来更像https://stackoverflow.com/a/41963237/2532070 - 在ticketr
目录中的django_project
目录,与manage.py
处于同一级别。
答案 1 :(得分:0)
所以基本上我的问题是几件事。我设置了一个新的Droplet并重新开始,我让它工作:
一旦完成,我必须重新启动gunicorn并使用以下方法刷新静态文件:
python manage.py collectstatic --noinput --clear
NB。确保应用程序与django_project位于同一目录中。 home / django / django_project< - there。