render_to_string
Posted: April 12th, 2010 | Author: Davo | Filed under: Django | Tags: render_to_response | No Comments »The render_to_string is similar to render_to_response but instead of sending the data to the response object it just saves the result as a string object.
This can be then used as normal string.
Example:
from django.template.loader import render_to_string
response = render_to_string('the_template.html', { 'varname': 'value' })
Be carefull, you CAN NOT do the following:
from django.template.loader import render_to_string
def my_view(request):
...
return render_to_string('the_template.html', { 'varname': 'value' }) # CRASH...!
But you CAN DO this instead:
from django.http import HttpResponse
from django.template.loader import render_to_string
def my_view(request):
...
return HttpResponse( render_to_string('the_template.html', { 'varname': 'value' }) )
