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
- Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
- Help text hyperlinks by sa2812 11 months, 3 weeks ago
Comments
Please login first before commenting.