40👍
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’.
6👍
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.
- [Django]-How to make Django QuerySet bulk delete() more efficient
- [Django]-How to use TailwindCSS with Django?
- [Django]-Django django-extensions commands unavailable ( graph_models )
2👍
http://docs.python.org/library/locale.html#locale.setlocale says that it is not thread-safe, which shouldnt be a problem running the dev server, but could cause you problems running it on a production server in a multi-threaded environment!
- [Django]-Can't compare naive and aware datetime.now() <= challenge.datetime_end
- [Django]-Django content types – how to get model class of content type to create a instance?
- [Django]-Django Tag model design
1👍
I know this is an old one, but I had this issue and I was able to keep using:
locale.setlocale( locale.LC_ALL, '' )
As I wanted to be able to run this code on a windows machine, linux machine and mac osx machine.
The above line should work with a windows machine by default, it won’t with a mac or linux machine.
If you are running the production server with apache, you’ll need to set up the user running the apache service with the locale you desire.
To do this (in ubuntu at least) go to /etc/apache2/ and edit the “envvars” file.
You’ll see in there it has this line by default:
export LANG=C
That is the reason you’re getting the error, change this to:
export LANG=en_CA.UTF-8
export LC_ALL=en_CA.UTF-8
Restart apache and you should be right as rain.
If you aren’t running apache and you’re getting that error then you just need to update the .bash_profile or .profile of the user running the webserver or python app, add the above two lines to the bash profile and restart the terminal session, start up the server and voila.
Hope this helps someone.
- [Django]-Error: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>
- [Django]-Using django-rest-interface
- [Django]-Django error: needs to have a value for field "…" before this many-to-many relationship can be used
0👍
I was having the same problem. It worked in the shell (manage.py shell), but not from the MVT. I had to use locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
because apparently, I didn’t have the en_CA.UTF-8
locale. Note the en_US...
as opposed to en_CA
. Just wanted to add the answer because it caught me again after rebuilding and had to find the comment to get fix it.
- [Django]-Using Django Managers vs. staticmethod on Model class directly
- [Django]-Convert an IP string to a number and vice versa
- [Django]-Django index page best/most common practice
0👍
I was getting the same error message using Djano, Nginx and uwsgi. To get the environment, as opposed to just Django, to use the correct locale, I had to add a line to wsgi.py:
wsgi.py
os.environ['LC_ALL'] = "en_GB.UTF-8"
(Note: in my case I was after British, not US, currency formatting so used _GB. Restarting the relevant services may be necessary for the change to take effect)
- [Django]-Determine variable type within django template
- [Django]-How to make an auto-filled and auto-incrementing field in django admin
- [Django]-Celery task schedule (Ensuring a task is only executed one at a time)