美文网首页
Django 后台标题修改

Django 后台标题修改

作者: 一斤蔬菜 | 来源:发表于2017-09-27 17:46 被阅读0次

默认标题是 Django Administration 或者是Django管理,目前网上很多教程都在说硬改admin的模板来实现修改名称的功能,对此我表示很难理解.
实际上只需要在admin.py中添加一点代码就可以实现修改.

先把源码部分贴出来:

class AdminSite(object):
    """
    An AdminSite object encapsulates an instance of the Django admin application, ready
    to be hooked in to your URLconf. Models are registered with the AdminSite using the
    register() method, and the get_urls() method can then be used to access Django view
    functions that present a full admin interface for the collection of registered
    models.
    """

    # Text to put at the end of each page's <title>.
    site_title = ugettext_lazy('Django site admin') # 这里

    # Text to put in each page's <h1>.
    site_header = ugettext_lazy('Django administration') # 这里

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

    # URL for the "View site" link at the top of each admin page.
    site_url = '/'

    _empty_value_display = '-'

    login_form = None
    index_template = None
    app_index_template = None
    login_template = None
    logout_template = None
    password_change_template = None
    password_change_done_template = None

我标注的三个地方就是定义站点名称的地方.
覆写他们很简单,只需要在项目的admin.py中,操作即可.

from django.contrib import admin
django.admin.site.site_title="自定义"
django.admin.site.site_header="自定义"
django.admin.site.index_title="自定义"

分别对应了<title>的结尾,页面的<h1>标题和网页<title>的前半部分.

相关文章

网友评论

      本文标题:Django 后台标题修改

      本文链接:https://www.haomeiwen.com/subject/eqouextx.html