Static files not found - Deploying Django on Heroku

后端 未结 1 1000
囚心锁ツ
囚心锁ツ 2021-01-15 13:59

I am trying to deploy a Django site on Heroku, but I\'m running into problems getting the app to locate my static files. I have used python manage.py collectstatic

相关标签:
1条回答
  • 2021-01-15 14:29

    Install dj-static package

    $ pip install dj-static
    

    Configure your static assets in settings.py:

    DEBUG = False
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )
    STATIC_ROOT = 'staticfiles'
    STATIC_URL = '/static/'
    

    Then, update your wsgi.py file to use dj-static:

    import os
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tomdeldridge.settings")
    
    from django.core.wsgi import get_wsgi_application
    from dj_static import Cling
    
    application = Cling(get_wsgi_application())
    
    0 讨论(0)
提交回复
热议问题