我在Django以下代码:问题试图与Python(Django的)格式化货币
import locale
locale.setlocale(locale.LC_ALL, '')
def format_currency(i):
return locale.currency(float(i), grouping=True)
它在开发模式中的某些计算机上工作,但只要我尝试将它部署在生产,我得到这个错误:
Exception Type: TemplateSyntaxError
Exception Value: Caught ValueError while rendering: Currency formatting is not possible using the 'C' locale.
Exception Location: /usr/lib/python2.6/locale.py in currency, line 240
奇怪的是,我可以在生产服务器上做到这一点,它会没有任何错误的工作:
python manage.py shell
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'en_CA.UTF-8'
>>> locale.currency(1, grouping=True)
'$1.00'
我..没有得到它。我
看看[babel](http://babel.edgewall.org/)图书馆:http://babel.edgewall.org/wiki/ApiDocs/0.9/babel.numbers – codeape 2010-06-01 20:40:06
我有同样的问题。它在shell(manage.py shell)中工作,但不是来自MVT。我不得不使用'locale.setlocale(locale.LC_ALL,'en_US.UTF-8')',因为显然,我没有'en_CA.UTF-8'语言环境。 – Furbeenator 2011-12-12 20:51:55