我在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