Suppose I have a middleware that detects whether a particular request comes from a particular machine:
class HomeIpMiddleware:
def process_request(self, request):
request.home_ip = False
ip = request.META.get("REMOTE_ADDR")
if ip == "123.456.789.101":
request.home_ip = True
return
Suppose I have a view that is used for public consumption but that generates an overlay on my site with extra admin information when home_ip=True
:
@cache_page(60 x 60)
def home(request):
output = {}
output['public_things'] = PUBLIC_DATA
if request.home_ip:
output['secret_things'] = SECRET_DATA
return render_to_response('home.html',
context_instance=RequestContext(request, {'output': output})
As this view is cached, if I access it from home_ip
the page is cached, with my secret information.
I accept that this is hacky, but is there a way to either:
- Disable site-wide in some middleware the cache for a
home_ip=True
request so that it doesn't generate a page cache; or - Make the
cache_page
decorator conditional onnot request.home_ip
?