我在Heroku上运行django应用程序。它可以很好地提供静态文件,当我将新静态文件推送到我的存储库时,它们会正确显示,但是当我对现有静态文件进行更改时(例如CSS改变)他们似乎没有被接受。
我的产品将其静态文件存储在我的每个django应用程序中名为static/
的文件夹中。然后,静态根位于名为static_root
的文件夹中。
当heroku对CSS文件执行python manage.py collectstatic
更改时,似乎不会传播到static_root
(尽管确实存在正确的原始CSS文件)。我尝试运行python manage.py collectstatic --clear
,然后将更改后的文件拖到static_root
,但服务器仍然提供旧版本,而一段时间之后旧版本的CSS文件就开始了回到static_root
。即使我尝试手动复制旧版本中的更改始终是服务器发送的版本,旧版本迟早会在static_root
中结束。
有谁知道为什么会这样?
为了证明我的配置是正确的,这是我的settings.py
和wsgi.py
settings.py
:
import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
ROOT_PATH = os.path.join(os.path.dirname(__file__), '..')
DEBUG = bool(int(os.getenv("DJANGO_DEBUG", 1)))
TEMPLATE_DEBUG = DEBUG
STATIC_ROOT = os.path.join(ROOT_PATH, 'jumpcut', 'static_root')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(ROOT_PATH, 'jumpcut', 'static'),
os.path.join(ROOT_PATH, 'viewer', 'static'),
os.path.join(ROOT_PATH, 'builder', 'static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'jumpcut.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'jumpcut.wsgi.application'
TEMPLATE_DIRS = (
os.path.join(ROOT_PATH, 'builder', 'templates'),
os.path.join(ROOT_PATH, 'viewer', 'templates'),
os.path.join(ROOT_PATH, 'jumpcut', 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Our custom apps
# REDACTED
)
wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpcut.settings")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
答案 0 :(得分:0)
由于dazedconfused的评论,我找到了一个解决方案。
问题是Heroku的ephemeral filesystem正在恢复我的更改。我的解决方案是从我的static_root
中删除.gitignore
,以便当我推送更改时Heroku会获取新的静态文件。