更改 Django/python 中 "Authentication and Authorization" 菜单的名称

Change name of the "Authentication and Authorization" menu in Django/python

我正在学习 python/Django 并设置我的第一个项目。一切顺利,但我一直在疯狂地寻找一些非常简单的东西。

有一个默认菜单项"Authentication and Authorization",我想更改名称。如果我需要扩展某些东西,我已经在模板中搜索过,我已经搜索过是否有 .po 文件或者没有,但我找不到它,也没有提示我应该在 [=13] 中覆盖哪个参数=] 进行设置。

我不是要安装多语言或某些高级本地化,只是想更改那个菜单项的名称:)

有什么想法吗?

这至少不能通过模板干净地完成..

您可以将授权应用详细名称 "authentication and authorization" 放入您自己的 .po 文件中(并按照 Django 文档进行翻译) 这样 Django 通常会使用你的名字。

创建指向原始 django.auth 模块的自定义 AppConfig 并覆盖 verbose_name。然后在 INSTALLED_APPS 中使用您的自定义 AppConfig 而不是原始 auth app.

https://docs.djangoproject.com/en/1.10/ref/applications/#configuring-applications

如果您使用的是自定义语言环境(请参阅 How to override the django admin translation?),那么最好的方法是将这些行添加到 django.po 文件中:

msgid "Authentication and Authorization"
msgstr "Your text for the auth app"

出于某种原因,许多本地化文件无法包含 "Authentication and Authorization" 字符串的翻译。像这样添加它(并使用上面 link 中提到的 compilemessages 命令)应该可以正常工作。

跟进 (Django 3.0):

在项目的某处创建一个包含自定义 AppConfig 的文件

# 'authconfig.py'
from django.apps import AppConfig

class CustomAuthConfig(AppConfig):
    name = 'django.contrib.auth'
    verbose_name = 'my super special auth name'

然后,在settings.py:

INSTALLED_APPS = [
    ...
    #'django.contrib.auth', # comment out to avoid duplicate apps
    'authconfig.CustomAuthConfig', # add this in for custom config of auth module
    ...
]