在Django管理中设置图标 [英] set favicon in django admin
问题描述
我需要为Django管理界面设置图标。
I need to set up a favicon for django admin interface.
最好在全球范围内这样做,而不必覆盖所有应用程序的模板。
It would be best to do it globally, without overriding templates for all apps.
最干净的方法是什么?我尝试在Django文档中搜索此内容,但未找到任何内容。
What is the cleanest way to do it? I tried searching Django documentation for this, but found nothing.
推荐答案
如果favicon位于'/ app / static / img / favicon中.ico,将其链接到该文件的{%block extrahead%}中:'/app/templates/admin/base_site.html'
If favicon is in '/app/static/img/favicon.ico', link it into the {% block extrahead %} of this file: '/app/templates/admin/base_site.html'
{% extends "admin/base.html" %}
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
{% block extrahead %}
<link rel="icon" href="{{STATIC_URL}}img/favicon.ico" sizes="48x48" />
{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
{% endblock %}
在settings.py INSTALLED_APPS中,请确保您的应用之前已列出django.contrib.admin。
In settings.py INSTALLED_APPS be sure your app is listed before django.contrib.admin.
要通过删除.pyc文件来测试摆脱模板缓存的方法: $ find。-name \ *。pyc\-删除。
To test get rid of template cache by deleting .pyc files: "$find . -name \"*.pyc\" -delete".
可与Django 1.8.12 Firefox,Chrome浏览器一起使用。
Works with Django 1.8.12 Firefox, Chrome.
这篇关于在Django管理中设置图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!