DjangoGirls / tutorial-extensions

Additional tasks for tutorial
https://tutorial-extensions.djangogirls.org
Other
163 stars 203 forks source link

Deploy to Heroku: whitenoise instructions are outdated and local_settings aren't currently applied locally #135

Closed john-sandall closed 1 year ago

john-sandall commented 4 years ago

1. Whitenoise instructions

Currently the tutorial has following guidance to install whitenoise (from https://tutorial-extensions.djangogirls.org/en/heroku/#mysitewsgipy):

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)

For whitenoise v4.* onwards (released Aug 2018), changelog states:

The WSGI integration option for Django (which involved editing wsgi.py) has been removed. > Instead, you should add WhiteNoise to your middleware list in settings.py and remove any reference to WhiteNoise from wsgi.py. See the documentation for more details. (The pure WSGI integration is still available for non-Django apps.)

Here's new guidelines (from http://whitenoise.evans.io/en/stable/django.html):

Edit your settings.py file and add WhiteNoise to the MIDDLEWARE list. The WhiteNoise middleware should be placed directly after the Django SecurityMiddleware (if you are using it) and before all other middleware:

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]

That’s it – WhiteNoise will now serve your static files. However, to get the best performance you should proceed to step 3 below and enable compression and caching.

To add automatic compression with the caching behaviour provided by Django’s ManifestStaticFilesStorage backend, add this also to settings.py

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

2. local_settings.py

Whilst better options are available for handling environmental settings configuration, I understand that using local_settings.py is easy to understand and does the job well enough. However, it's not being applied locally in these instructions: https://tutorial-extensions.djangogirls.org/en/heroku/#mysitelocalsettingspy

To apply these locally, we just need to add following to the bottom of settings.py:

# Override with local_settings if it exists
try:
    from .local_settings import *
except ImportError:
    pass
amakarudze commented 1 year ago

Closing this since we removed Heroku tutorial.