简体   繁体   English

Heroku 上未加载静态文件:Django 1.6

[英]Static files not loading on Heroku : Django 1.6

I am deploying my Django application on Heroku.我正在 Heroku 上部署我的 Django 应用程序。 It has been deployed successfully.它已成功部署。 But static files are not loading.但是没有加载静态文件。

I followed this link, but when Whitenoise 3.x is included, the command我按照这个链接,但是当包含 Whitenoise 3.x 时,命令

python manage.py collectstatic --noinput

fails.失败。

my Procfile:我的Procfile:

python manage.py collectstatic --noinput
web:python manage.py runserver
web: gunicorn MovieTracker.wsgi --log-file -
heroku ps:scale web=1

I have also tried with :我也试过:

heroku config:set DISABLE_COLLECTSTATIC=1

and also :并且 :

heroku config:set DISABLE_COLLECTSTATIC=0

The settings.py file is: 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'

with whitenoise enabled, ERROR:启用白噪声后,错误:

构建错误

您应该删除 STATIC_ROOT 子路径上的前导斜杠。

STATIC_ROOT = os.path.join(BASE_DIR, "tracker/static")

There is version conflict between whitenoise and Django in the project.项目中whitenoise和Django存在版本冲突。 The project uses Django 1.6 whereas whitenoise version that was being used was该项目使用 Django 1.6 而正在使用的 whitenoise 版本是

Whitenoise 3.x白噪声 3.x

Compatibility follows:兼容性如下:

Django 1.6 and lower with Whitenoise 2.x带有 Whitenoise 2.x 的 Django 1.6 及更低版本

Settings are given in this link for whitenoise 2.x.链接中给出了白噪声 2.x 的设置。

Django 1.7 and above with Whitenoise 3.x带有 Whitenoise 3.x 的 Django 1.7 及更高版本

Follow this for whitenoise 3.x.按照这个来处理 whitenoise 3.x。

Set the version in requirements.txt accordingly.相应地在 requirements.txt 中设置版本。

In the Procfile, just the following line is enough.在 Procfile 中,只需以下行即可。

web: gunicorn MovieTracker.wsgi --log-file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM