Render to file

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

  1. Template Tag Render Decorator by stephen_mcd 4 years, 1 month ago
  2. Pygmentify a code using template filter by tamizhgeek 2 years, 11 months ago
  3. render_as_template template tag by cogat 5 years, 1 month ago
  4. Render (with RequestContext) by alcides 5 years, 9 months ago
  5. Twitter template tags and filters by moxypark 3 years, 8 months ago

Comments

jezdez (on April 9, 2008):

indeed, very useful!

#

tekNico (on April 12, 2008):

Yeah, useful while living in fantASCII land: then you realize you need codecs.open instead. ;-)

#

davmuz (on July 31, 2012):

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))``

#

(Forgotten your password?)