Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
john-sandall opened this issue Dec 27, 2019 · 1 comment

Comments

@john-sandall
Copy link

john-sandall commented Dec 27, 2019

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
Copy link
Contributor

Closing this since we removed Heroku tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants