【问题标题】:How do I fix this error in my Django settings.py?如何在我的 Django settings.py 中修复此错误?
【发布时间】:2019-12-17 18:28:09
【问题描述】:

我正在尝试使用 i18n 进行一些翻译。我在 setting.py 文件中的 TEMPLATES 中导入了一些库。

问题是,如果我导入 django.core.context_processors.i18n,我的 Iapp 会显示错误并且它不会工作。

settings.py 文件中的我的模板

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'django.core.context_processors.i18n', #i18n
        ],
    },
},

]

如果我导入最后一行,我的应用会显示此错误:

ModuleNotFoundError 在 /myapp2/ 没有名为“django.core.context_processors”的模块

提前谢谢你

【问题讨论】:

    标签: django django-templates internationalization settings django-i18n


    【解决方案1】:

    在较新版本的 django 中,这应该是 django.template.context_processors.i18n。见https://docs.djangoproject.com/en/3.0/ref/templates/api/#django-template-context-processors-i18n

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 2018-07-15
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      相关资源
      最近更新 更多