【问题标题】:Change name of the "Authentication and Authorization" menu in Django/python在 Django/python 中更改“身份验证和授权”菜单的名称
【发布时间】:2016-08-29 16:11:29
【问题描述】:

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

有一个默认菜单项“身份验证和授权”,我想更改名称。如果我需要扩展某些东西,我已经在模板中搜索过,我已经搜索过是否有 .po 文件或其他文件,但我找不到它,也没有提示我应该在 admin.py 中覆盖哪个参数来设置它。

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

有什么想法吗?

【问题讨论】:

    标签: python django admin


    【解决方案1】:

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

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

    【讨论】:

    • 您能给我们详细介绍一下这种方法吗?
    【解决方案2】:

    跟进Lorenzo's answer(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
        ...
    ]
    

    【讨论】:

    • 我使用了与此类似的方法,django 迁移停止同步模型权限。
    【解决方案3】:

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

    您可以将身份验证应用程序详细名称“身份验证和授权”放在自己的 .po 文件中(并按照 Django 文档进行翻译) 这样 Django 通常会使用你的名字。

    【讨论】:

      【解决方案4】:

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

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

      由于某些原因,许多本地化文件未能包含“身份验证和授权”字符串的翻译。像这样添加它(并使用上面链接中提到的 compilemessages 命令)应该可以正常工作。

      【讨论】:

        猜你喜欢
        • 2020-03-26
        • 2014-11-13
        • 2017-07-21
        • 2022-01-25
        • 2010-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多