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
- find even number by Rajeev529 2 weeks, 4 days ago
- Form field with fixed value by roam 1 month, 1 week ago
- New Snippet! by Antoliny0919 1 month, 2 weeks ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 4 months ago
- get_object_or_none by azwdevops 7 months, 4 weeks ago
Comments
Please login first before commenting.