[Django]-Error: "unsupported locale setting" on Python / OSX

6πŸ‘

βœ…

This did the trick for me, write the one you want verbatim. I have 2 exception blocks because I use linux and osx:

Where in your code do you set it? This works for me, since the Linux and OSX machines vary and I use my code on both, I wrote this exception block:

try:
    import locale
    locale.setlocale(locale.LC_ALL, 'en_US.utf8')
except Exception:
    try:
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
    except Exception as e:
        messages.error(request, 'An error occurred: {0}'.format(e))

My locale outputs:

locale
LANG="en_CA.UTF-8"
LC_COLLATE="en_CA.UTF-8"
LC_CTYPE="en_CA.UTF-8"
LC_MESSAGES="en_CA.UTF-8"
LC_MONETARY="en_CA.UTF-8"
LC_NUMERIC="en_CA.UTF-8"
LC_TIME="en_CA.UTF-8"
LC_ALL=
πŸ‘€radtek

0πŸ‘

Probably you do not have the locales. Add it as follows:

Check which locales are supported:

locale -a

Add the locales you want (for example pt):

sudo locale-gen pt_BR

sudo locale-gen pt_BR.UTF-8

Run this update command:

sudo update-locale 

Leave a comment