[Django]-Block content on admin template not overridden

1👍

{% block content %} is populated by index.html which extends base_site.html therefore even if you do any changes in base_site.html it will be overriden by index.html‘s {% block content %}. The possible solution is to delete everything in index.html‘s block content and call {{block.super}} so if you do any changes in base_site.html they will be passed to index.html.

2👍

In order to get {% block content %} to work extending the admin’s template, you need to create an index.html file inside the folder admin, located in the template’s DIR folder, which is the folder mentioned in Django’s documentation, usually templates/admin/index.html, then in this file you can extend the admin/index.html file and replace the block content, for instance:

{% extends "admin/index.html" %}
{% load static %}


{% block content %}
{{ block.super }}
<p>this works</p>
{% endblock %}

To get the template’s DIR, you can open up the settings.py file, it’s an option like this

TEMPLATES = [
        { 'DIRS': [BASE_DIR / 'templates'], }
]

Leave a comment