【问题标题】:Django admin reuse headerDjango 管理员重用标头
【发布时间】:2019-07-23 01:51:57
【问题描述】:

我想在我的自定义视图中重用 django 管理页面的标题,这样我就可以使用“查看站点、更改密码和注销”,这样我就不必重新编码那部分了。

是否可以只扩展标题部分?

【问题讨论】:

    标签: python django django-admin


    【解决方案1】:

    也许你不能。因为这些是admin/base.html 模板的组成部分。因此,您可以创建一个新的基本模板并从此admin/base.html 复制标题部分。像这样:

    {% load i18n static %}<!DOCTYPE html>
    {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
    <html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
    <head>
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
    {% block extrastyle %}{% endblock %}
    {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}">{% endif %}
    {% block extrahead %}{% endblock %}
    {% block responsive %}
        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" type="text/css" href="{% static "admin/css/responsive.css" %}">
        {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% static "admin/css/responsive_rtl.css" %}">{% endif %}
    {% endblock %}
    {% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE">{% endblock %}
    </head>
    {% load i18n %}
    
    <body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}"
      data-admin-utc-offset="{% now "Z" %}">
    
    <!-- Container -->
    <div id="container">
    
        {% if not is_popup %}
        <!-- Header -->
        <div id="header">
            <div id="branding">
            {% block branding %}{% endblock %}
            </div>
            {% block usertools %}
            {% if has_permission %}
            <div id="user-tools">
                {% block welcome-msg %}
                    {% trans 'Welcome,' %}
                    <strong>{% firstof user.get_short_name user.get_username %}</strong>.
                {% endblock %}
                {% block userlinks %}
                    {% if site_url %}
                        <a href="{{ site_url }}">{% trans 'View site' %}</a> /
                    {% endif %}
                    {% if user.is_active and user.is_staff %}
                        {% url 'django-admindocs-docroot' as docsroot %}
                        {% if docsroot %}
                            <a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
                        {% endif %}
                    {% endif %}
                    {% if user.has_usable_password %}
                    <a href="{% url 'admin:password_change' %}">{% trans 'Change password' %}</a> /
                    {% endif %}
                    <a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>
                {% endblock %}
            </div>
            {% endif %}
            {% endblock %}
            {% block nav-global %}{% endblock %}
        </div>
        <!-- END Header -->
    </div>
    <!-- END Container -->
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2012-06-25
      • 1970-01-01
      • 2014-09-28
      • 2010-10-12
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      相关资源
      最近更新 更多