Django Caching - Remove caching for certain pages

孤者浪人 提交于 2019-12-23 12:26:17

问题


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:


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):
     # ...


来源:https://stackoverflow.com/questions/8856675/django-caching-remove-caching-for-certain-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!