python - Django Admin - 更改标题 'Django administratio

如何更改 django 管理 header 中的“Django 管理”文本?

“自定义管理员”文档中似乎没有涵盖它。

最佳答案

从 Django 1.7 开始,您不需要覆盖模板。您现在可以实现 site_header , site_title , 和 index_title自定义属性 AdminSite为了轻松更改管理站点的页面标题和标题文本。创建一个 AdminSite 子类并将您的实例挂接到您的 URLconf:

admin.py:

from django.contrib.admin import AdminSite
from django.utils.translation import ugettext_lazy

class MyAdminSite(AdminSite):
    # Text to put at the end of each page's <title>.
    site_title = ugettext_lazy('My site admin')

    # Text to put in each page's <h1> (and above login form).
    site_header = ugettext_lazy('My administration')

    # Text to put at the top of the admin index page.
    index_title = ugettext_lazy('Site administration')

admin_site = MyAdminSite()

urls.py:

from django.conf.urls import patterns, include
from myproject.admin import admin_site

urlpatterns = patterns('',
    (r'^myadmin/', include(admin_site.urls)),
)

更新:正如 oxfn 所指出的,您可以简单地设置 site_header在您的 urls.pyadmin.py 中直接没有子类化 AdminSite:

admin.site.site_header = 'My administration'

关于python - Django Admin - 更改标题 'Django administration' 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4938491/

相关文章:

python - 如何将 Pandas 数据添加到现有的 csv 文件中?

python - 如何在 python-3.x 中使用字典格式化字符串?

python - 如何打印字典的键?

linux - 如何在 Bash 中给定超时后杀死子进程?

python - 在 Python 中获取大文件的 MD5 哈希

python - 您需要安装 postgresql-server-dev-X.Y 来构建服务器端扩展

python - 为什么使用 Python 的 os 模块方法而不是直接执行 shell 命令?

python - 为什么我不能在 python 中创建一个轮子?

linux - 从ssh注销后如何使程序继续运行?

linux - 好的 Linux (Ubuntu) SVN 客户端