配置不正确:导入模块django.contrib.locale时出错:“没有名为locale的模块”

时间:2014-12-19 06:22:07

标签: python django internationalization

我正在使用django收到此错误。

我正在使用django国际化。我创建了语言文件。我没有问题地运行服务器,但是当向网站发出请求时,向我显示以下信息:

Traceback (most recent call last):
      File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
        self.result = application(self.environ, self.start_response)
      File "/Users/mcaste/Developer/Projects/django/venv_python_2_8_django_1_6/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
        return self.application(environ, start_response)
      File "/Users/mcaste/Developer/Projects/django/venv_python_2_8_django_1_6/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
        self.load_middleware()
      File "/Users/mcaste/Developer/Projects/django/venv_python_2_8_django_1_6/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
        mw_class = import_by_path(middleware_path)
      File "/Users/mcaste/Developer/Projects/django/venv_python_2_8_django_1_6/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_by_path
        sys.exc_info()[2])
      File "/Users/mcaste/Developer/Projects/django/venv_python_2_8_django_1_6/lib/python2.7/site-packages/django/utils/module_loading.py", line 21, in import_by_path
        module = import_module(module_path)
      File "/Users/mcaste/Developer/Projects/django/venv_python_2_8_django_1_6/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
        __import__(name)
    ImproperlyConfigured: Error importing module django.contrib.locale: "No module named locale"

我有这个:

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.locale.LocaleMiddleware',
)

1 个答案:

答案 0 :(得分:1)

我认为,locale middlware应该出现在常见的中间件之前:docs say that

  

......它应该出现在CommonMiddleware之前   因为CommonMiddleware需要一个激活的语言才能   解析请求的网址。

MIDDLEWARE_CLASSES = (
  'django.contrib.sessions.middleware.SessionMiddleware',
  'django.middleware.locale.LocaleMiddleware',
  'django.middleware.common.CommonMiddleware',
)