我似乎无法解决生产中静态文件的问题。我知道主机服务应该在调试关闭时处理生产中的静态文件,但由于某些原因,heroku无法执行此操作。 我按照Django的指示安装了whitenoise,它确实解决了我在推送到heroku时遇到的另一个问题。但是当我打开调试时,假静态文件仍然停止工作。这是我的制作设置: 进口口 来自django.conf导入设置
DEBUG = True
TEMPLATE_DEBUG = True
DATABASES= settings.DATABASES
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
SHARE_URL = "https://fast-reaches-2219.herokuapp.com/?ref="
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
和wsgi.py文件:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
try:
from dj_static import Cling
application = Cling(get_wsgi_application())
except:
pass