Fighting client-side caching in Django

前端 未结 7 931
傲寒
傲寒 2020-11-27 13:18

I\'m using the render_to_response shortcut and don\'t want to craft a specific Response object to add additional headers to prevent client-side caching.

I\'d like to

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 14:10

    Actually writing my own middleware was easy enough:

    from django.http import HttpResponse
    
    
    class NoCacheMiddleware(object):
    
        def process_response(self, request, response):
    
            response['Pragma'] = 'no-cache'
            response['Cache-Control'] = 'no-cache must-revalidate proxy-revalidate'
    
            return response
    

    Still doesn't really behave like i wanted but so neither does the @never_cache decorator

提交回复
热议问题