0

我正在尝试将一个新的 Django/Wagtail 应用程序部署到 Heroku,但遇到了麻烦。

我正在关注本教程,该教程一直有效到最后一节“在 Heroku 上提供静态资产”。但是,当我使用 将应用程序推送到 Heroku 时git push heroku master,它会失败并出现以下错误:

...
remote:        182 static files copied to '/app/static', 182 post-processed.
remote: 
remote: -----> Running run_compress
remote: -----> Compressing static files
remote:        Unknown command: 'compress'
remote:        Type 'manage.py help' for usage.
remote: 
remote:  !     Push rejected, failed to compile Python app
remote: 
remote: Verifying deploy....
remote: 
remote: !   Push rejected to myapp.
remote: 
To https://git.heroku.com/myapp.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/myapp.git'
$

大概 Heroku 在使用 Django Compressor 时遇到了问题,尽管教程没有指定它的安装,所以我不确定。本教程指定了安装一个名为Heroku Django Cookbookrun_compress的东西,它在一个文件中指定了一个bash,如下所示:

#!/usr/bin/env bash
set -eo pipefail

indent() {
    RE="s/^/       /"
    [ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE"
}

MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' | head -1)
MANAGE_FILE=${MANAGE_FILE:2}

echo "-----> Compressing static files"
python $MANAGE_FILE compress 2>&1 | indent

echo

所以它似乎manage.py compress不起作用。否则它可能与 Whitenoise 有关,因为那是教程中失败的部分。不过,似乎安装正确。以下是我的相关行settings.py

...
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

COMPRESS_OFFLINE = True
COMPRESS_CSS_FILTERS = [
    'compressor.filters.css_default.CssAbsoluteFilter',
    'compressor.filters.cssmin.CSSMinFilter',
]
COMPRESS_CSS_HASHING_METHOD = 'content'
...

最后,这是我的requirements.txt

beautifulsoup4==4.4.1
dj-database-url==0.4.1
dj-static==0.0.6
Django==1.9.6
django-appconf==1.0.2
django-compressor==2.0
django-modelcluster==1.1
django-taggit==0.18.3
django-toolbelt==0.0.1
django-treebeard==4.0.1
djangorestframework==3.3.3
gunicorn==19.6.0
html5lib==0.9999999
Pillow==3.2.0
psycopg2==2.6.1
python-dateutil==1.5
pytz==2016.4
rcssmin==1.0.6
requests==2.10.0
rjsmin==1.0.12
six==1.10.0
static3==0.7.0
Unidecode==0.4.19
wagtail==1.4.5
whitenoise==3.2
Willow==0.3.1

有任何想法吗?欢迎所有线索。谢谢!

4

1 回答 1

2

看起来你没有添加compressorINSTALLED_APPS.

另外值得一提的是,Wagtail从 1.4 版开始不再依赖django_compressor,所以如果你不需要django_compressor's 的功能,你可以从你的项目中删除它。

于 2016-06-10T08:21:44.813 回答