Django Apache WSGI locale and "Currency formatting is not possible using the 'C' locale."
Posted by Gene at 22:04 on Sun 25 Apr 2010 -- 2 Comments

If you want to use the python method locale.currency() to format numbers, you need to make sure you aren't set to the 'C' locale.

You can use the following and serve the code up with Django runserver with no problem. The Python documentation says that this call '...sets the locale...user’s default setting (typically specified in the LANG environment variable).'

import locale
locale.setlocale(locale.LC_ALL, '')

locale.currency(10.50)

If you use Apache, and WSGI to serve up your Django App, you need to include the locale value explicitly. Otherwise you may find the error: Currency formatting is not possible using the 'C' locale.

import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

locale.currency(10.50) # $10.50 USD

Incidentally, for my code to be internationalized, I will need to set the locale based on a User preference anyway, so relying on the server environment's setting would not be correct even if it worked.

  • I've found a more complete locale example that might be worth looking at: http://djangosnippets.org/snippets/1825/

    - EyePulp
  • Just what I needed. Thank!

    - Vasili