Django static files on heroku

后端 未结 5 1520
借酒劲吻你
借酒劲吻你 2020-12-05 05:09

I deployed a django app to heroku, using \"git push heroku master\" which worked absolutely fine.

I then created a second app on the same git using \"heroku create s

5条回答
  •  情话喂你
    2020-12-05 06:02

    For Django 2.1.7, I did the following changes in order to work:

    1. Added whitenoise to requirements.txt in addition to gunicorn

    2. Project settings.py should have the following:

      A) static settings:

      STATIC_URL = '/static/'
      STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
      
      STATICFILES_DIRS = [
          os.path.join(BASE_DIR, "static"), 
      ]
      

      B) Add whitenoise to middleware:

      MIDDLEWARE = [
         .....
         'whitenoise.middleware.WhiteNoiseMiddleware',
      ]
      

    Finally commit and push your changes then deploy your app peacefully.

提交回复
热议问题