i got a bad rendering in template when using locale.format

78 views
Skip to first unread message

aliane abdelouahab

unread,
Oct 18, 2012, 9:22:54 AM10/18/12
to Tornado Web Server
hi
i just discovered the [locale][1] module in Python, and i've tried to
use it with Tornado Template but i get a bizarre bizarre rendering, so
1000 will become 1�000, so i cant get the good separator, i tried
both: the comma (system default) and the space (french)
here is the code:

import locale
locale.setlocale(locale.LC_ALL, "french_France")

and in the template:

{% import locale %}
<span class="prix">The price: {{locale.format("%d", price,
grouping=True)}} DA</span>

any ideas?
NB: changed the font and always the same bizarre � that is showing.

aliane abdelouahab

unread,
Oct 18, 2012, 9:40:55 AM10/18/12
to Tornado Web Server
NB: it seems that i dont render here the value, it's an interrogation
mark in a diamond shape.

aliane abdelouahab

unread,
Oct 18, 2012, 9:45:52 AM10/18/12
to Tornado Web Server
update2: there is '{:,}'.format(price) but this only uses a comma as a
separator.

aliane abdelouahab

unread,
Oct 18, 2012, 10:52:26 AM10/18/12
to Tornado Web Server
update:
using babel.numbers worked good.
i've found this
https://groups.google.com/group/python-tornado/browse_thread/thread/bbed7993f82322ce

Frank Smit

unread,
Oct 19, 2012, 5:05:44 AM10/19/12
to python-...@googlegroups.com
You can also use PyICU. It's not documented and they point you to the
C++ API documentation, but it's good enough since the Python API looks
a lot like the C++ API.

aliane abdelouahab

unread,
Oct 19, 2012, 10:07:39 AM10/19/12
to Tornado Web Server
will be faster than Babel? because i need only the currency formatting
option, and it worked good using Babel.

On 19 oct, 11:05, Frank Smit <fr...@61924.nl> wrote:
> You can also use PyICU. It's not documented and they point you to the
> C++ API documentation, but it's good enough since the Python API looks
> a lot like the C++ API.
>
> On Thu, Oct 18, 2012 at 4:52 PM, aliane abdelouahab
>
>
>
>
>
>
>
> <alabdeloua...@gmail.com> wrote:
> > update:
> > using babel.numbers worked good.
> > i've found this
> >https://groups.google.com/group/python-tornado/browse_thread/thread/b...

Frank Smit

unread,
Oct 19, 2012, 11:23:45 AM10/19/12
to python-...@googlegroups.com
I don't know if it's faster. I use it because it works on Python 3.

aliane abdelouahab

unread,
Oct 19, 2012, 5:27:16 PM10/19/12
to Tornado Web Server
finally i think i'll stick with Babel, because PyICU need visual
studio to compile on windows, and am trying to test the application on
windows (i've a laptop that uses optimus and it's not good with linux)
thank you again :)
Reply all
Reply to author
Forward
0 new messages