Django Caching - Remove caching for certain pages

2019-06-24 17:08发布

I would like to turn caching off for certain pages when that view is accessed. It's for a page that simply queries model objects.

it seems like when 'django.middleware.cache.FetchFromCacheMiddleware', is enabled, it requires another "refresh" from the browser to see the latest data.

Is there any way to prevent this?

Thank you.

1条回答
姐就是有狂的资本
2楼-- · 2019-06-24 17:43

https://docs.djangoproject.com/en/dev/topics/cache/#controlling-cache-using-other-headers

If you want to use headers to disable caching altogether, django.views.decorators.cache.never_cache is a view decorator that adds headers to ensure the response won't be cached by browsers or other caches. Example:

from django.views.decorators.cache import never_cache

@never_cache
def myview(request):
     # ...
查看更多
登录 后发表回答