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))
|
More like this
- Caching XHTML render_to_response by smoonen 4 years, 10 months ago
- Partial OpenID provider implementation from idproxy.net by simon 5 years, 10 months ago
- table with n items per row using custom modulo tag by elgreengeeto 4 years, 5 months ago
- a simple tag with context by dsblank 3 years, 5 months ago
- Switch/case tags. by jacobian 5 years, 10 months ago
Comments
indeed, very useful!
#
Yeah, useful while living in fantASCII land: then you realize you need codecs.open instead. ;-)
#
The Django template engine renders as UTF-8, so you have to write a UTF-8 file.
``import codecs
codecs.open(filename, 'w', 'utf-8').write(render_to_string(template, context))``
#