django和Heroku的静态文件夹无效

时间:2017-04-26 16:15:23

标签: django heroku

我尝试在Heroku上发布一个django项目,但我遇到静态文件问题。 这是我的配置:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

但是Heroku回来了:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_02a3e2abd7f176139303f077e32a2e9b/static'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...

我没有解决方案,我理解这个问题,但不知道如何解决它:( 我的项目结构如下:

├── Procfile
├── manage.py
├── my_project
│   ├── __init__.py
│   ├── settings
│   │   ├── __init__.py
│   │   ├── base.py
│   │   ├── dev.py
│   │   └── prod.py
│   ├── urls.py
│   └── wsgi.py
├── requirements.txt
├── runtime.txt
├── static
└── staticfiles

关于Django或Heroku的文档没有解释何时环境分割设置:(

1 个答案:

答案 0 :(得分:0)

我只是通过设置:

解决了我的问题
MEDIA_ROOT = 'media'
STATIC_ROOT = 'static'