yanik
yanik

Reputation: 808

Django: decorator for catching response context from classic views

I have simple classic Django view:

@log_me
def single(request):
    item = Items.objects.all()[0]
    return render_to_response('ololo.html', {'object': item})

How can i catch context in @log_me decorator? I need this: {'object': item}

Thank you.

Upvotes: 1

Views: 134

Answers (1)

dgel
dgel

Reputation: 16806

This isn't possible. render_to_response will render the template with the context and return a completed HttpResponse object. The HttpResponse object would be available in your view decorator but the context data is already rendered into the response.

You'll need to think of another approach. A custom middleware may be an option, take a look at process_template_response.

Upvotes: 2

Related Questions