Reputation: 6997
I've been developing an application using Django for the past a year. The application was written in a Debian environment, the development and testing was entirely done in a debain machine.
Recently, I decided to move the application to my local Mac OS X based laptop. using port's I did a virtual environment and pulled my project from github. When I try to runserver, am getting "unsupported locale setting" exception.
My application uses locale heavily, I noticed though the language setting in my machine is set for en_US.UTF-8 while on the debian machine it was en_US.UTF8. I don't know if the dash is the reason why it is failing though.
My application is using django-localeurl for creating language code url schema for i10n and i18n.
below is the exception am getting
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/en/
Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['localeurl',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.comments',
'libraries.plugins.piston',
'nani',
'haystack',
'compressor',
'libraries.plugins.social_auth',
'registration',
'djcelery',
'django.contrib.markup',
'south',
'libraries.plugins.storages',
'libraries.plugins.django_messages',
'merlin',
'seacucumber',
'timezones',
'treebeard',
'apps.core',
'apps.core.mediastore',
'apps.core.accounts',
'apps.core.mazvars',
'apps.core.mazguard',
'apps.core.system',
'apps.core.sponsorship',
'apps.portal.default',
'apps.portal.support',
'apps.portal.pages',
'apps.portal.blog',
'apps.portal.developer',
'apps.listing',
'apps.listing.postfix',
'apps.listing.category',
'apps.listing.post',
'apps.listing.home',
'apps.listing.shoutout',
'apps.listing.taggables',
'apps.listing.comment',
'apps.listing.badge',
'apps.listing.geo',
'apps.listing.reputation',
'apps.mzn.shorturl',
'grappelli.dashboard',
'grappelli',
'django.contrib.admin',
'django.contrib.admindocs',
'debug_toolbar']
Installed Middleware:
('localeurl.middleware.LocaleURLMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'apps.core.middleware.FallbackLocaleMiddleware',
'apps.core.accounts.middleware.LoggingMiddleware',
'apps.core.accounts.middleware.CompleteEmail',
'apps.core.accounts.middleware.setref',
'apps.core.accounts.middleware.FollowUser',
'apps.core.accounts.middleware.UnFollowUser',
'apps.core.accounts.middleware.FraudLocked',
'apps.core.middleware.DefaultAdminLocaleMiddleware',
'apps.core.middleware.DefaultSiteMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/Users/mo/Projects/pythonic/mazban/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/mo/Projects/pythonic/mazban/mazban/apps/listing/home/views.py" in home
23. cal = render_event_calendar_widget(language_code=request.LANGUAGE_CODE)
File "/Users/mo/Projects/pythonic/mazban/mazban/apps/listing/post/event_views.py" in render_event_calendar_widget
115. return cal.render()
File "/Users/mo/Projects/pythonic/mazban/mazban/apps/core/utils.py" in render
81. [day for day in cal.formatweekheader(self.wh).split(' ')]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/calendar.py" in formatweekheader
297. return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/calendar.py" in <genexpr>
297. return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/calendar.py" in formatweekday
511. with TimeEncoding(self.locale) as encoding:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/calendar.py" in __enter__
490. _locale.setlocale(_locale.LC_TIME, self.locale)
File "/Users/mo/Projects/pythonic/mazban/lib/python2.7/locale.py" in setlocale
531. return _setlocale(category, locale)
Exception Type: Error at /
Exception Value: unsupported locale setting
any idea's what could be causing this?
update:
when I logged in to terminal and wrote "locale" I got the below
(mazban)Mohammed-Mughrabis-MacBook-Pro:mazban mo$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
Upvotes: 1
Views: 4855
Reputation: 36300
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))
Upvotes: 3
Reputation: 6997
for future reference, I solved the problem by exporting LC_ALL as 'en_US' which solved my problem
export LC_ALL='en_US'
Upvotes: 3