Turn off caching of static files in Django development server

后端 未结 9 2229
灰色年华
灰色年华 2020-11-30 04:52

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:

<
9条回答
  •  囚心锁ツ
    2020-11-30 05:28

    For newer Django, the way middleware classes are written has changed a bit.

    Follow all the instructions from @aaronstacy above, but for the middleware class, use this:

    class NoCache(object):
        def __init__(self, get_response):
            self.get_response = get_response
    
        def __call__(self, request):
            response = self.get_response(request)
            response['Cache-Control'] = 'must-revalidate, no-cache'
            return response
    

提交回复
热议问题