Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

WhiteNoise middleware added in the wrong place #32

Open
pupeno opened this issue Nov 10, 2018 · 3 comments
Open

WhiteNoise middleware added in the wrong place #32

pupeno opened this issue Nov 10, 2018 · 3 comments

Comments

@pupeno
Copy link

pupeno commented Nov 10, 2018

From WhiteNoise's documentation, the middleware should be added after the security one:

Edit your settings.py file and add WhiteNoise to the MIDDLEWARE_CLASSES list, above all other middleware apart from Django’s SecurityMiddleware

http://whitenoise.evans.io/en/stable/#quickstart-for-django-apps

Yet django-heroku adds it before the security middleware.

@ntravis
Copy link

ntravis commented Nov 14, 2018

Looks pretty straightforward as to why:

# Insert Whitenoise Middleware.
try:
config['MIDDLEWARE_CLASSES'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE_CLASSES']))
except KeyError:
config['MIDDLEWARE'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE']))

For a fix, I've submitted a PR. Not as clean-looking, but does operate within the expected parameters of whitenoise. You could make an assumption about SecurityMiddleware always being first in the list, but that seems fraught. You have to go out to a new variable because list.index modifies the original list, rather than returning the newly modified list, so the original list(config...) won't work since that created an on-the-fly reference.

@superandrew
Copy link

+1

@udit-001
Copy link

Any updates on this so far? It doesn't seem to work with Django 2.2 😞

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants