from django.template.response import TemplateResponse

def decorator(view):

    def wrapper(request, *args, **kwargs):
        r = view(request, *args, **kwargs)
r.context_data = {'foo': 'bar'}
return r.render()
return wrapper

@decorator
def index(request):
    return TemplateResponse(request, 'index.html')
Django: add context to response using decorator