简体   繁体   English

django在Mac OS X上不受支持的语言环境设置

[英]django unsupported locale setting on Mac OS X

I've been developing an application using Django for the past a year. 过去一年来,我一直在使用Django开发应用程序。 The application was written in a Debian environment, the development and testing was entirely done in a debain machine. 该应用程序是在Debian环境中编写的,开发和测试完全在debain机器上完成。

Recently, I decided to move the application to my local Mac OS X based laptop. 最近,我决定将应用程序移动到基于本地Mac OS X的笔记本电脑上。 using port's I did a virtual environment and pulled my project from github. 使用端口,我做了一个虚拟环境,并从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. 我的应用程序大量使用语言环境,我注意到尽管我的机器中的语言设置是为en_US.UTF-8设置的,而在debian机器上是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. 我的应用程序使用django-localeurl为i10n和i18n创建语言代码url模式。

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 当我登录终端并输入“ locale”时,我得到了以下内容

(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=

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: 这对我有用,因为Linux和OSX机器各不相同,并且我在两者上都使用我的代码,所以我写了这个异常块:

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))

供将来参考,我通过将LC_ALL导出为'en_US'解决了问题

export LC_ALL='en_US'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM