Wrapper for render_to_response that allows you to pass in a optional preinitialized HttpResponse object. Helpful when you want to want to set cookies or just add some extra initialization to your HttpResponse. If no HttpResponse is passed in the normal render_to_response is called. It's called exactly like the normal render_to_response except that you can pass in a kwargs response pair if you wish.
Like so:
code render_response('index.html',{'aparam': val}, context_instance=RequestContext(request),response=my_response)
1 2 3 4 5 6 7 8 9 | def render_response(*args, **kwargs):
response = kwargs.pop('response', None)
if response == None:
from django.shortcuts import render_to_response
return render_to_response(*args, **kwargs)
else:
from django.template import loader
response.content = loader.render_to_string(*args, **kwargs)
return response
|
More like this
- Add Toggle Switch Widget to Django Forms by OgliariNatan 2 days, 9 hours ago
- get_object_or_none by azwdevops 3 months, 3 weeks ago
- Mask sensitive data from logger by agusmakmun 5 months, 2 weeks ago
- Template tag - list punctuation for a list of items by shapiromatron 1 year, 7 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 8 months ago
Comments
Please login first before commenting.