'Add extra context to admin index page

In my admin.py of my admin dashboard app I added this following code:

class MyAdminSite(admin.AdminSite):
    def index(self, request, extra_context=None):
        if extra_context is None:
            extra_context = {}
        extra_context['foo'] = 'bar'
        return super(MyAdminSite, self).index(request, extra_context)

I try to display the context in the index.html (Line 15) but it doesn't work. "bar" suppose to be displayed between "Performance" and "Test". Did I miss any step required? Thanks

{% extends "admin/base_site.html" %}
{% load i18n static %}

{% block breadcrumbs %}{% endblock %}

{% block content %}
    <div class="content">
        <div class="row">
            <div class="col-12">
                <div class="card card-chart">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-sm-6 {{ direction.panel }}">
                                <h5 class="card-category">{% trans "Total Shipments" %}</h5>
                            <h2 class="card-title">{% trans "Performance" %}{{ foo }}Test</h2>
                            </div>
                            ...
{% endblock %}

"bar" should appear between "Performance" and "Test"



Solution 1:[1]

Try the code below:

urlpatterns = [
       path('admin/', admin.site.urls , {'extra_context': {
       'pro': Product.objects.all(),}}),

]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gavriel Cohen