Currency filter

1
2
3
4
5
6
7
8
9
from django import template
import locale
locale.setlocale(locale.LC_ALL, '')
register = template.Library()
 
 
@register.filter()
def currency(value):
    return locale.currency(value, grouping=True)

Comments

MasonM (on July 24, 2008):

Cool, I didn't know about the locale module. I had to change line 3 to "locale.setlocale(locale.LC_ALL, 'en_US')" for this to work on a shared server I use.

#

cornbread (on August 14, 2008):

This works great on my ubuntu-hardy laptop but I can't get it to work on my ubuntu-gutsy server.

I get some kind of a Locale C error.

#

cornbread (on August 18, 2008):

FIGURED IT OUT!!!

I had to set up the language pack on my ubuntu-server... Apparently this doesn't get done by default on the server version of ubuntu.

sudo ./install-language-pack en_US then restart x and you're golden.

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.