pythondjangodjango-staticfilesstatic-filesdisable

Turn off caching of static files in Django development server


Is there an easy way to turn off caching of static files in Django's development server?

I'm starting the server with the standard command:

python manage.py runserver

I've got settings.py configured to serve up static files from the /static directory of my Django project. I've also got a middleware class that sets the Cache-Control header to must-revalidate, no-cache for development, but that only seems to affect URLs that are not in my /static directory.


Solution

  • Assuming you're using django.views.static.serve, it doesn't look like it - but writing your own view that just calls django.views.static.serve, adding the Cache-Control header should be rather easy.