静态文件未在 Heroku 上加载:Django 1.6
Static files not loading on Heroku : Django 1.6
我正在 Heroku 上部署我的 Django 应用程序。它已成功部署。但是静态文件没有加载。
我遵循了thislink,但是当包含Whitenoise3.x时,命令
python manage.py collectstatic --noinput
失败。
我的程序文件:
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'
启用白噪声,错误:
您应该删除 STATIC_ROOT 子路径中的前导斜杠。
STATIC_ROOT = os.path.join(BASE_DIR, "tracker/static")
项目中whitenoise和Django版本冲突。
该项目使用 Django 1.6,而使用的 whitenoise 版本是
Whitenoise 3.x
兼容性如下:
Django 1.6 and lower with Whitenoise 2.x
this link 中给出了 whitenoise 2.x 的设置。
Django 1.7 and above with Whitenoise 3.x
关注 this 以获得白噪声 3.x。
相应地在requirements.txt中设置版本。
在 Procfile 中,只需以下行即可。
web: gunicorn MovieTracker.wsgi --log-file
我正在 Heroku 上部署我的 Django 应用程序。它已成功部署。但是静态文件没有加载。
我遵循了thislink,但是当包含Whitenoise3.x时,命令
python manage.py collectstatic --noinput
失败。
我的程序文件:
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'
启用白噪声,错误:
您应该删除 STATIC_ROOT 子路径中的前导斜杠。
STATIC_ROOT = os.path.join(BASE_DIR, "tracker/static")
项目中whitenoise和Django版本冲突。 该项目使用 Django 1.6,而使用的 whitenoise 版本是
Whitenoise 3.x
兼容性如下:
Django 1.6 and lower with Whitenoise 2.x
this link 中给出了 whitenoise 2.x 的设置。
Django 1.7 and above with Whitenoise 3.x
关注 this 以获得白噪声 3.x。
相应地在requirements.txt中设置版本。
在 Procfile 中,只需以下行即可。
web: gunicorn MovieTracker.wsgi --log-file