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
- Form field with fixed value by roam 2 weeks ago
- New Snippet! by Antoliny0919 3 weeks ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 7 months ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Please login first before commenting.