Задать вопрос

Тел: +7 965 3737 888

433

Просмотров

3

Ответов

Render to file

<p>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.</p>

Вопрос полезен? Да0/Нет0
file_4779.py(175.0б)
None

Ответы (3):

Ответdavmuz:31.07.2012
Ответ полезен? Да0/Нет0

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

Ответteknico:12.04.2008
Ответ полезен? Да0/Нет0

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

Ответjezdez:09.04.2008
Ответ полезен? Да0/Нет0

indeed, very useful!