I noticed recently that Firefox seems to cache form fields very aggressively, particularly tickbox values. This can result in the cached values being displayed instead of the updated content from the server. It usually happens when the submitted form returns to the same URL – e.g. an Update Profile page – giving the impression that changes haven’t been saved. Bad Firefox! A re-direct after POST doesn’t seem to resolve the issue.
The only way to force Firefox to display the updated content is to set the ‘no-cache’ HTTP header. Fortunately Django has a cache framework that can be used out-of-the-box to do this individually for each view. The key piece is the @cache_control decorator.
The solution very simple, just import the decorator and add it to the view that handles the form processing. The full docs are on the Django site. I’ve included a short example below.
from django.views.decorators.cache import cache_control @cache_control(no_cache=True) def my_form_view(request): ...rest of view
The result can be confirmed by viewing the http response headers, the Firefox Web Developer extension is a handy tool for this. If everything is working you’ll see:
Cache-Control: no-cache
Job Done. Thanks Django!

1 comment so far ↓
.Fortunately Django has a cache framework that can be used out-of-the-box to do this individually for each view. The key piece is the @cache_control decorator?
Leave a Comment