Templetor: is there a way i could use python locale or something?

38 views
Skip to first unread message

Florian Lagg

unread,
Oct 2, 2012, 7:01:13 AM10/2/12
to we...@googlegroups.com
Hi, 

I really enjoy the template engine, I use it some time now for web output, and I try to use it to edit the xml-content of OpenOffice odt files (to be able to design and generate pdf's, I'll open source this later.). 

What I really would need, is to do some formatting I need to do in the python statements in the template.

Is there any way I could do something like that?
('%.2f' % 1.2333333).replace('.', ',')
or something like:
import locale
locale.setlocale(locale.LC_ALL, 'FR')
locale.format('%.2f', 1.2333333)

Thanks in advance for your help, hope we have a solution to this! 
Yours Florian.

Andrey Kuzmin

unread,
Oct 12, 2012, 8:02:57 AM10/12/12
to we...@googlegroups.com
You may define your own function and pass them as template globals.

template_globals = {
    "format_float":  lambda x:  ('%.2f' % x).replace('.', ',')
}
render = template.render(your_template_dir, globals=template_globals, base='layout')

Then in your templates you'll be able to use $format_float(x)
Reply all
Reply to author
Forward
0 new messages