You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

来源:互联网 发布:php实现uv pv ip统计 编辑:程序博客网 时间:2024/06/07 00:43

【问题】Heroku部署报错:

remote:        django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.remote: remote:  !     Error while running '$ python manage.py collectstatic --noinput'.

【分析原因】

1.错误提示没有设置STATIC_ROOT,查看设置STATIC_ROOT的原py文件:

settings.py:

# Heroku设置if os.getcwd() == '/app':    import dj_database_url    DATABASES = {        'default': dj_database_url.config(default='postgres://localhost')    }    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')    ALLOWED_HOSTS = ['*']    PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))    STATIC_ROOT = 'staticfiles'    STATICFILES_DIRS = (        os.path.join(PROJECT_ROOT, 'static'),        )

可以看到,settings.py中设置了STATIC_ROOT,没生效的原因是if 模块条件不满足

2.设置debug模式查看变量:

heroku config:set DEBUG_COLLECTSTATIC=1

参见官网:https://devcenter.heroku.com/articles/django-assets

remote: ****** Collectstatic environment variables:remote: remote:        CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:remote:        EXPORT_PATH=/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/bin/../exportremote:        SOURCE_VERSION=cd6b464f5547d9ad4e76d44a43726bebb7c30368remote:        PROFILE_PATH=/tmp/build_cfa1044d9f6f7ba51f5503a4fd86a6e2/.profile.d/python.shremote:        DEBUG_COLLECTSTATIC=1remote:        BUILDPACK_LOG_FILE=/dev/fd/3remote:        LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:remote:        CACHE_DIR=/app/tmp/cacheremote:        PYTHONUNBUFFERED=1remote:        DEFAULT_PYTHON_STACK=cedar-14remote:        LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/libremote:        BIN_DIR=/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/binremote:        DYNO=run.6619remote:        PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin::/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/tmp/codon/vendor/bin:/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/:/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-popremote:        ENV_DIR=/tmp/d20171027-69-1ccgm4mremote:        RECOMMENDED_PYTHON_VERSION=python-3.6.2remote:        C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:remote:        PWD=/tmp/build_cfa1044d9f6f7ba51f5503a4fd86a6e2remote:        BPLOG_PREFIX=buildpack.pythonremote:        LANG=en_US.UTF-8remote:        CACHED_PYTHON_STACK=heroku-16remote:        STACK=heroku-16remote:        SHLVL=3remote:        REQUEST_ID=cb62d053-d9e7-58a0-a77c-eeed27ca3efaremote:        HOME=/appremote:        LATEST_2=python-2.7.14remote:        LATEST_3=python-3.6.2remote:        PIP_UPDATE=9.0.1remote:        BUILD_DIR=/tmp/build_cfa1044d9f6f7ba51f5503a4fd86a6e2remote:        WARNINGS_LOG=/tmp/tmp.QRkojcYlAeremote:        DEFAULT_PYTHON_VERSION=python-3.6.2remote:        PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkgconfig:/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:remote:        _=/usr/bin/env

可以看到,当前工作目录不是'/app',且每次生成的目录都不一样(build后面的一串不固定),应该获取HOME目录。

PWD=/tmp/build_cfa1044d9f6f7ba51f5503a4fd86a6e2HOME=/app

【解决方法】

if os.getcwd() == '/app':          #获取当前工作目录改为:if os.environ['HOME'] == '/app':   #获取HOME目录
阅读全文
0 0
原创粉丝点击