python - Django 管理员重用标头
问题描述
我想在我的自定义视图中重用 django 管理页面的标题,这样我就可以使用“查看站点、更改密码和注销”,这样我就不必重新编码那部分了。
是否可以仅扩展标题部分?
解决方案
可能你不能。因为这些是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>
推荐阅读
- linux - 使用 openvpen 而不是 openvpn3 连接到 staging vpn
- django - Django项目中docker-compose中的Postgres连接问题
- amazon-web-services - 调用 SSH 时 Shell 脚本停止
- elasticsearch - Elasticsearch 对过滤条件组进行“或”搜索
- c++ - 部分模板特化:std::allocator_traits?
- homebrew - 尝试在 MacOS 上更新 Homebrew 但收到错误消息“LibreSSL 错误”
- json - 阅读 REST API JSON 回复
- leaflet - 如何以编程方式获取 PixiOverlay 标记并通过绘制的边界获取它们的属性
- c# - 如何将“System.Windows.Controls.TextBlock”转换为“System.Windows.Controls.Control”WPF C#
- windows - UWP 画布像素操作