本文介绍了如何更改Wagtail的默认语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用无头的Wa,并且想要将默认的后端语言更改为葡萄牙语(pt-pt).遵循ag的文档:

I'm using headless Wagtail and want to change the default backend language to Portuguese (pt-pt).Following wagtail's docs:

# settings.py

USE_I18N = True

LANGUAGE_CODE = "pt-pt"

然后为什么我尝试发布wagtail页面时出现以下错误:

Then why I try to publish a wagtail page I get the following error:

请求方法:POST请求URL: http://127.0.0.1:8000/admin/pages/11/edit/

Request Method: POST Request URL:http://127.0.0.1:8000/admin/pages/11/edit/

Django版本:3.1.2 Python版本:3.9.0已安装的应用程序:[首页",搜索",新闻","about_us",产品",仪表板",'wagtail_headless_preview','wagtail.contrib.forms','wagtail.contrib.redirects','wagtail.embeds','wagtail.sites','wagtail.users','wagtail.snippets','wagtail.documents','wagtail.images','wagtail.search','wagtail.admin','wagtail.core','wagtail.api.v2','modelcluster','taggit','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','rest_framework','corsheaders']已安装的中间件:['django.middleware.locale.LocaleMiddleware','corsheaders.middleware.CorsMiddleware','django.middleware.common.CommonMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','django.middleware.security.SecurityMiddleware','wagtail.contrib.redirects.middleware.RedirectMiddleware']

Django Version: 3.1.2 Python Version: 3.9.0 Installed Applications:['home', 'search', 'news', 'about_us', 'product', 'dashboard','wagtail_headless_preview', 'wagtail.contrib.forms','wagtail.contrib.redirects', 'wagtail.embeds', 'wagtail.sites','wagtail.users', 'wagtail.snippets', 'wagtail.documents','wagtail.images', 'wagtail.search', 'wagtail.admin','wagtail.core', 'wagtail.api.v2', 'modelcluster', 'taggit','django.contrib.admin', 'django.contrib.auth','django.contrib.contenttypes', 'django.contrib.sessions','django.contrib.messages', 'django.contrib.staticfiles','rest_framework', 'corsheaders'] Installed Middleware:['django.middleware.locale.LocaleMiddleware','corsheaders.middleware.CorsMiddleware','django.middleware.common.CommonMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','django.middleware.security.SecurityMiddleware','wagtail.contrib.redirects.middleware.RedirectMiddleware']

回溯(最近通话最近):文件" C:\ Users \ diogo \ OneDrive-特拉蒙斯蒙特阿尔索大学Douro \ Marfon \ venv \ lib \ site-packages \ django \ core \ handlers \ exception.py",第52行,在内部响应= get_response(请求)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ django \ core \ handlers \ base.py",_get_response中的第195行响应= wraped_callback(request,* callback_args,** callback_kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ django \ views \ decorators \ cache.py",第49行,在 wrapped_view_func中响应= view_func(request,* args,** kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ admin \ urls_ init .py",170行,在包装器中返回view_func(request,* args,** kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ admin \ auth.py",第179行,在decorated_view中响应= view_func(request,* args,** kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ django \ views \ generic \ base.py",视线85返回self.dispatch(request,* args,** kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ admin \ views \ pages \ edit.py",第138行,正在派遣中返回super().dispatch(请求)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ django \ views \ generic \ base.py",第116行,正在派遣中返回处理程序(请求,* args,** kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ admin \ views \ pages \ edit.py",第257行,在帖子中返回self.form_valid(self.form)文件'C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto Douro大学\ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ admin \ views \ pages \ edit.py",第283行,在form_valid中返回self.publish_action()文件"C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ admin \ views \ pages \ edit.py",第329行,在publish_action中修订版= self.page.save_revision(文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ core \ models.py",第1385行,在save_revision中self.full_clean()文件"C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ wagtail-2.11rc1-py3.9.egg \ wagtail \ core \ models.py",1033行,在full_clean中super().full_clean(* args,** kwargs)文件" C:\ Users \ diogo \ OneDrive-Tras-os-Montes e Alto大学Douro \ Marfon \ venv \ lib \ site-packages \ django \ db \ models \ base.py",行1390,干净整齐引发ValidationError(errors)

Traceback (most recent call last): File "C:\Users\diogo\OneDrive -Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\django\core\handlers\exception.py",line 52, in innerresponse = get_response(request) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\django\core\handlers\base.py",line 195, in _get_responseresponse = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\django\views\decorators\cache.py",line 49, in wrapped_view_funcresponse = view_func(request, *args, **kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\admin\urls_init.py",line 170, in wrapperreturn view_func(request, *args, **kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\admin\auth.py",line 179, in decorated_viewresponse = view_func(request, *args, **kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\django\views\generic\base.py",line 85, in viewreturn self.dispatch(request, *args, **kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\admin\views\pages\edit.py",line 138, in dispatchreturn super().dispatch(request) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\django\views\generic\base.py",line 116, in dispatchreturn handler(request, *args, **kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\admin\views\pages\edit.py",line 257, in postreturn self.form_valid(self.form) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e Alto Douro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\admin\views\pages\edit.py",line 283, in form_validreturn self.publish_action() File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\admin\views\pages\edit.py",line 329, in publish_actionrevision = self.page.save_revision( File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\core\models.py",line 1385, in save_revisionself.full_clean() File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\wagtail-2.11rc1-py3.9.egg\wagtail\core\models.py",line 1033, in full_cleansuper().full_clean(*args, **kwargs) File "C:\Users\diogo\OneDrive - Universidade de Tras-os-Montes e AltoDouro\Marfon\venv\lib\site-packages\django\db\models\base.py", line1390, in full_cleanraise ValidationError(errors)

异常类型:/admin/pages/11/edit/处的ValidationError异常值:{'locale':['id为1的语言环境实例不存在.']}

Exception Type: ValidationError at /admin/pages/11/edit/ ExceptionValue: {'locale': ['locale instance with id 1 does not exist.']}

有什么建议吗?我还缺少一些额外的步骤吗?

Any suggestion? Is there some extra step I'm missing?

推荐答案

您正在阅读Wagtail 2.0中的文档,该文档已经过时了.Wagtail 2.11的国际化支持文档(在撰写本文时尚未发布)可以在以下位置找到: https://docs.wagtail.io/en/latest/advanced_topics/i18n.html

You're following documentation from Wagtail 2.0, which is very outdated. The documentation for Wagtail 2.11's internationalisation support (unreleased at the time of writing) can be found here: https://docs.wagtail.io/en/latest/advanced_topics/i18n.html

如此处所述,您在设置文件中配置语言,还需要在数据库中设置区域设置记录.这可以在数据迁移中完成,也可以通过启用 wagtail.locales 应用并通过设置"->管理员中的区域设置区域:

As mentioned there, when you configure languages in your settings file you also need to set up Locale records in the database. This can be done in a data migration, or by enabling the wagtail.locales app and going through the Settings -> Locales area in the admin:

INSTALLED_APPS = [
    # ...
    'wagtail.locales',
    # ...
]

这篇关于如何更改Wagtail的默认语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 01:55