Django 推送到 Heroku:"Unknown command: 'compress'"?
Django push to Heroku: "Unknown command: 'compress'"?
我正在尝试将新的 Django/Wagtail 应用程序部署到 Heroku,但遇到了问题。
我正在关注 this tutorial,直到最后一节 "Serving static assets on Heroku"。但是,当我使用 git push heroku master
将应用程序推送到 Heroku 时,它失败并出现此错误:
...
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 Cookbook 的东西,它在 bash
文件中指定 run_compress
,如下所示:
#!/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
有什么想法吗?欢迎所有线索。谢谢!
您似乎没有将 compressor
添加到 INSTALLED_APPS
。
还值得一提的是,Wagtail 从 1.4 版开始就没有 longer depends on django_compressor
,所以如果您不需要 django_compressor
的功能,可以将其从您的项目中删除。
我正在尝试将新的 Django/Wagtail 应用程序部署到 Heroku,但遇到了问题。
我正在关注 this tutorial,直到最后一节 "Serving static assets on Heroku"。但是,当我使用 git push heroku master
将应用程序推送到 Heroku 时,它失败并出现此错误:
...
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 Cookbook 的东西,它在 bash
文件中指定 run_compress
,如下所示:
#!/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
有什么想法吗?欢迎所有线索。谢谢!
您似乎没有将 compressor
添加到 INSTALLED_APPS
。
还值得一提的是,Wagtail 从 1.4 版开始就没有 longer depends on django_compressor
,所以如果您不需要 django_compressor
的功能,可以将其从您的项目中删除。