set favicon in django admin

kurtgn picture kurtgn · Jan 23, 2016 · Viewed 8.6k times · Source

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.

What is the cleanest way to do it? I tried searching Django documentation for this, but found nothing.

Answer

user3526918 picture user3526918 · May 5, 2016

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 %}

In settings.py INSTALLED_APPS be sure your app is listed before django.contrib.admin.

To test get rid of template cache by deleting .pyc files: "$find . -name \"*.pyc\" -delete".

Works with Django 1.8.12 Firefox, Chrome.