我正在Heroku上部署我的Django应用程序。它已成功部署。但是静态文件没有加载。
我按了this链接,但是当包含Whitenoise 3.x时,命令
python manage.py collectstatic --noinput
失败。
我的Procfile:
python manage.py collectstatic --noinput
web:python manage.py runserver
web: gunicorn MovieTracker.wsgi --log-file -
heroku ps:scale web=1
我也尝试过:
heroku config:set DISABLE_COLLECTSTATIC=1
还有:
heroku config:set DISABLE_COLLECTSTATIC=0
settings.py文件是:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tracker',
)
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',
# 'whitenoise.middleware.WhiteNoiseMiddleware',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "/tracker/static")
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
启用了whitenoise,错误:
答案 0 :(得分:1)
您应该删除STATIC_ROOT子路径上的前导斜杠。
STATIC_ROOT = os.path.join(BASE_DIR, "tracker/static")
答案 1 :(得分:0)