开发者

In Django, can I set vary_on_cookie globally?

开发者 https://www.devze.com 2023-02-11 19:07 出处:网络
When developing a Django app, I can use the vary_on_cookie decorator to make sure that upstream caches use the session cookie in addition to the URL to distinguish

When developing a Django app, I can use the vary_on_cookie decorator to make sure that upstream caches use the session cookie in addition to the URL to distinguish betw开发者_运维百科een different pages.

I have a lot of view functions and all of them now require this header. Is it possible to specify this behavior once (maybe in the settings file for the entire site or at least for an entire app)? Or do I really have to repeat that decorator in front of every single view function?

Thank you very much for your help...


Sounds like you will want to write your own middleware and modify each request to include any extra headers that you want included on each request.

Creating middleware is easy and you will probably be interested in the process_response method, as you can simply modify the response and you're done.

To modify the headers of an HttpResponse check out the docs here.


UsingSessionMiddleware adds Cookie to the Cache-Control headers for every request.

0

精彩评论

暂无评论...
验证码 换一张
取 消