Problems trying to format currency with Python (Django)

On the production server, try

locale.setlocale( locale.LC_ALL, 'en_CA.UTF-8' )

instead of

locale.setlocale( locale.LC_ALL, '' )

When you use '', the locale is set to the user's default (usually specified by the LANG environment variable). On the production server, that appears to be 'C', while as a test user it appears to be 'en_CA.UTF-8'.


I ran into a similar problem where I run Django app via PyCharm (JetBrain's IDEA 12 based IDE), it was getting the same issue of

Currency formatting is not possible using the 'C' locale.

where as it worked fine by then running python manage.py runserver would just work fine. After some digging I found a thread discussion about environment variable LC_ALL here

And it turned out if you edit the "Run Configration" and add an environment variable, it will work just fine. See screenshot below. Hope this helps others who encounter the same problem. Locale Setting Environment Variable

Tags:

Python

Django