Search code examples
pythondjangoherokucollectstatic

How do I disable whitenoise for local development of my Django project?


I've set up a Django project deployed on Heroku using the Heroku Django project template. Heroku's template uses whitenoise to collect static files in a /static/ directory located on my project root.

This is great for my production environment; Heroku runs "manage.py collectstatic" each time I push new files to my server. However, it's a pain when developing locally: every time I change my static files (e.g., css), I have to manually run "python manage.py collectstatic" before seeing changes on my development server.

Is there an easy way to disable whitenoise on my local machine so that I don't have to run "python manage.py collectstatic" every time I want to see changes to local static files?

I've tried creating a separate "development_settings.py" file and removing all references to whitenoise in that file, but it doesn't work because whitenoise is still referenced in wsgi.py, which causes errors.


Solution

  • WhiteNoise has a setting called WHITENOISE_AUTOREFRESH for exactly this reason.

    From the WhiteNoise Docs:

    WHITENOISE_AUTOREFRESH: Rechecks the filesystem to see if any files have changed before responding. This is designed to be used in development where it can be convenient to pick up changes to static files without restarting the server. For both performance and security reasons, this setting should not be used in production.

    The default setting of this is the value of settings.DEBUG so it should be on by default if you're running a development server.