Sometimes, we want to override admin CSS in Python Django.
In this article, we’ll look at how to override admin CSS in Python Django.
How to override admin CSS in Python Django?
To override admin CSS in Python Django, we can set the css
file of the Media
class in the model admin class.
For instance, we write
class MyModelAdmin(admin.ModelAdmin):
class Media:
js = ('js/admin/my_own_admin.js',)
css = {
'all': ('css/admin/my_own_admin.css',)
}
in admin.py to add the Media
class in the MyModelAdmin
class.
In it, we set the css
field to a dict with the all
key set to the CSS file path.
Conclusion
To override admin CSS in Python Django, we can set the css
file of the Media
class in the model admin class.