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

Viewed 1625

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

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

To locate django's base.html file, assuming you are using Linux and virtualenv and your virtual environment folder, py_env (your own virtual environment name) folder is inside your $HOME directory. Then the path to your base.html is:

$HOME/py_env/lib/python<your_version_of_python>/site-packages/django/contrib/admin/templates/admin

For me, I use termux on Android and the full path to my base.html is:

/data/data/com.termux/files/home/py_env/lib/python3.8/site-packages/django/contrib/admin/templates/admin

Windows with Anaconda environment manager django and base.html path is

/c/Program Files/Anaconda3/envs/myenv/lib/site-packages/django/contrib/admin/templates/admin/base.html
Related