Install favicon in django admin

I need to configure favicon for django admin interface.

It would be best to do this globally, without redefining the patterns for all applications.

What is the cleanest way to do this? I tried to find Django documentation for this, but didn't find anything.

+11
source share
3 answers

If favicon is located in '/app/static/img/favicon.ico', link it to {% 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 %}

In settings.py INSTALLED_APPS, make sure your application is listed before django.contrib.admin.

, .pyc: "$ find. -name \" *. pyc\ "-delete".

Django 1.8.12 Firefox, Chrome.

+10

Django base.html , my_app/templates/admin/base.html.

{% block extrahead %} .

   {% extends 'admin/base.html' %}
    {% load staticfiles %}
    {% block javascripts %}
        {{ block.super }}
    <script type="text/javascript" src="{% static 'app/js/action.js' %}"></script>

    {% endblock %}

    {% block extrahead %}
        <link rel="shortcut icon" href="{% static 'app/img/favicon.ico'  %}" />
    {% endblock %}
    {% block stylesheets %}

        {{ block.super }}
    {% endblock %}
+3

Extend admin/base.htmlin the template template/admin/base_site.htmland add the favicon link to the block of additional headers

{% extends "admin/base.html" %}
{% load staticfiles %}
...
{% block extrahead %}
    <link rel="shortcut icon" href="{% static 'relative/path/to/favicon.ico' %}" />
{% endblock %}
+2
source

Source: https://habr.com/ru/post/1625601/


All Articles