Search code examples
djangodjango-admindjango-staticfiles

Where is Django base.html file? Add additional static style sheet


I would like copy & use the admin/base.html file in my templates/accounts folder. So I can hopefully include one additional custom style sheet in the head. I have used the:

python -c "import django; print(django.__path__)"

previously to locate & copy the user admin forms. When I follow the path generated from the line above I now get a path to .py files rather than .html files.

path to files

.py files

Does anyone have a copy of the base.html file? Or can suggest the cleanest way to include one additional style sheet?

This is what I am trying to avoid if possible.

base_site.html

{% extends "admin/base.html" %}
{% block title %}{{ title }} | {{ site_title|default:_('MY SITE') }}{% endblock %}

<!--CAN THIS BE ADDED TO THE HEAD OF base.html-->
{% block body_head %}
<link href="{% static 'css/custom.css' %}" rel="stylesheet">
{% endblock body_head %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">MY SITE</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}

Solution

  • for this {% extends "admin/base.html" %} django will get first found file base.html in subdir admin in all template dirs, but if you want to look on source of django.contrib.admin base.html, you can find it in the:

    DJANGO_PATH/contrib/admin/templates/admin/base.html