fbzyx
fbzyx

Reputation: 349

Django admin: every app with different custom base_site.html

Hi I have been trying to customize my admin page and I have some application specific admin pages that require custom javascript and css. I would like to have different base_site.html within the template/admin/ of each app including the required javascript and css. The thing is that only the changes of the base_site.html of the first registered app (inside the settings.py file) are shown.

Thank you.

-app1
    -templates
        -admin
            -base_site.html
-app2
    -templates
        -admin
            -base_site.html
-app3
    -templates
        -admin
            -base_site.html
-manage.py

Upvotes: 0

Views: 702

Answers (1)

datosula
datosula

Reputation: 1596

If you just want to add some custom javascript and css to your admin you'd better use ModelAdmin asset definitions. See django docs for more. Something like this:

class ArticleAdmin(admin.ModelAdmin):
    class Media:
        css = {
            "all": ("my_styles.css",)
        }
        js = ("my_code.js",)

As for base_site.html, you will not be able to override it for each application, it is general template not application specific template. But anyways, you could override/extend change_form.html and change_list.html templates, based on each application or even for each model. And tree should be as follows:

-app1
    -templates
        -admin
            -app1
                -change_form.html
                -change_list.html

And if you use extension rather than overriding you may access header using extrahead and extrastyle blocks.

/app1/templates/admin/app1/change_form.html

{% extends "admin/change_form.html" %}
{% block extrahead %}
{{ block.super }}
... your code here ...
{% endblock %}

Upvotes: 1

Related Questions