00:00 Overriding Django Admin Templates. The Django developers implemented the admin using the Django template mechanism. This made their job a little bit easier, but it also benefits you by allowing you to override those templates.
The exact location will depend on your system, but will largely be the same as the one onscreen, where
(venv) represents your Python virtual environment and
(python) is the Python version you’re using.
00:41 Here, you can see the admin templates being shown in Finder on my own system, and the main thing to notice is there’s a lot of them. The Django template engine has a defined order for loading templates.
00:54 When it loads a template, it uses the first template that matches the name. You can override admin templates by using the same directory structure and file names. The admin templates come in two directories.
registration/ is for password changes and logging in and out. To customize the logout page, you need to override the right file. The relative path leading to the file has to be the same as the one being overridden.
The template engine searches directories in the
'DIRS' option before the application directories, so anything with the same name as an admin template will be loaded instead. To see this in action, copy Django’s default
logged_out.html file into your
templates/registration/ directory, and then modify it as seen onscreen now.
02:30 If you click LOG OUT, then you’ll see the customized message. Django admin templates are deeply nested and maybe not that intuitive, but you do have full control over their presentation if you need it.
02:45 Some packages including Grappelli and Django Admin Bootstrap have fully replaced the Django admin templates to change their appearance. Projects like these can sometimes not yet be compatible with the latest Django version, so you may need to follow their changes closely. That said, if you want to see the power of overriding admin templates, they’re well worth checking out.
Become a Member to join the conversation.