Reputation: 3418
I've been updating recently to django 1.3 and got the following issue:
I have a base template 'base.html' which depends on the state (saved in request.session) of the user session, and therefore should be rendered every time a page is loaded/reloaded. All my pages are extended from this base template according to common use:
{% extends "base.html" %}
This has not been an issue before, but now I noticed that the base template gets somehow cached (i.e. it is not getting reloaded on every request). I'm using the following template loaders:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
Can somebody please advice me on how to disable this caching??? Let me know if you need some further information - thanks in advance.
EDIT: Pages are rendered from within views.py as follows:
render_to_response('page.html', RequestContext(request,{}))
Upvotes: 0
Views: 559
Reputation: 3418
The actual problem was client side caching. The problem is solved site wide with the following middleware:
from django.utils.cache import add_never_cache_headers
class DisableClientSideCachingMiddleware(object):
def process_response(self, request, response):
add_never_cache_headers(response)
return response
Upvotes: 0
Reputation: 30473
This might be too late but I ran into the same problem recently, and I found another (possibly simpler) solution:
In Django's cache framework, you can use a decorator called @cache_control to take care of the header you are sending, for example:
from django.views.decorators.cache import cache_control
@cache_control(must_revalidate=True)
def my_view(request):
...
will tell the caches to revalidate every time the view is accessed.
Upvotes: 1