我可以将异常的消息语言更改为中文吗?
try:
new_project = admin_conn.conn.identity.create_project(**project_params) # create_project
print (new_project, new_project.id, "new project created")
except Exception as e:
print (e.message)
render(request, '/register/', {"errors": e.message.encode('utf-8')})
e.message.encode('utf-8')
是英语,如何将其更改为中文?
编辑
由于异常的消息有许多类型错误,所以我不能转换每个错误,因此在Django中是否还有其他方便的方法可以做到这一点?
是的,您可以使用internationalization package
i18n
,然后放置您的内容b/w {% trans %}
标签。
确保在项目设置中确保 在html 如果您有 和不要foget 将USE_I18N = True
{% load i18n %}
{% trans "Successfully landed on this page" %}
message
变量。{% trans {{message}} %}
chineese
添加为您的语言。