- April 8, 2008
- template render file
- 4 (after 4 ratings)
As a demo, I was asked to write a
render_to_file() function to load a template and render it to a file. Turns out it's amazingly easy, and I think it's a neat trick to have in your bag of tools.
1 2 3 4
from django.template.loader import render_to_string def render_to_file(template, filename, context): open(filename, "w").write(render_to_string(template, context))