def get_context(max_depth=4):
    import inspect
stack = inspect.stack()[2:max_depth]
context = {}
for frame_info in stack:
    frame = frame_info[0]
arg_info = inspect.getargvalues(frame)
if 'context' in arg_info.locals:
    context = arg_info.locals['context']
break
return context
Django — доступ к RequestContext из пользовательского фильтра