Your First Admin Customization3:43 with Lacey Williams Henschel
Learn how to do your very first customizations of the admin. Replace the “Django Administration” text in the header with something more appropriate to your own project.
Now that we've reviewed the basics, 0:00 let's start changing some things around to make our admin site work better for us. 0:01 You know how when you log into the admin it says, Django Administration at the top? 0:07 That doesn't make a lot of sense to a regular user. 0:12 It might make more sense for 0:16 that to say something like, Learning Site Administration. 0:18 Or something that matches whatever your project is all about. 0:21 One quick point, for 0:25 this section we're actually overwriting a template that's included in Django so 0:27 we had to add a couple of things that can be a little confusing. 0:32 Don't worry, I'll walk you through it. 0:35 Your workspace is all set up with the files you need, so go ahead and launch it. 0:38 The first things to note is that we have this new sub-folder 0:44 in the templates directory at the project level. 0:47 This directory, admin, which is a namespace for the admin app, 0:50 contains the template we need to modify, base_site.html. 0:54 base_site.html is a template that ships with Django. 0:59 You have to dig for it in the Django source code to find it, so 1:04 let's take a look. 1:07 The Django source code lives on GitHub at github.com/django/django. 1:08 Anyone can go looking for it, and anyone can request to make changes or 1:14 improvements to it. 1:18 Feel free to poke around and take a look. 1:20 That's a great way to learn more about Django and how it's set up. 1:22 To find the templates for the admin, we need to go into the django directory and 1:26 then into contrib, and then into admin. 1:32 Once we're in the admin directory, we click on the templates directory. 1:35 And then we click on admin again. 1:39 You see why namespacing is really important, right? 1:42 So from here, 1:45 we can see all of the templates that come with the admin in Django. 1:46 The one we need is base_site.html. 1:51 So all we would do is copy and paste all of this code 1:54 into a template in our own project, also called base_site.html. 1:58 I've included links to the Django documentation in the teacher's notes, so 2:04 you can look there to find all of this for yourself. 2:08 For now, your workspace already has this template included in your project. 2:11 Now if you open up base_site.html, you see that we've reproduced 2:16 the directory structure from the Django source code in our own project. 2:21 We have this admin directory inside a templates directory, and 2:25 then base_site.html is inside the admin directory. 2:29 Reproducing this ensures that the namespacing is consistent, so 2:33 our file overrides what's in Django's file in the source code. 2:37 So see here on line 6, 2:42 inside of this H1 tag where it has the default Django administration? 2:44 We wanna replace all of this with Learning Site Administration. 2:49 Now save it, and let's go ahead and start our server. 2:58 And remember to use the 8000 port. 3:08 And now whenever we refresh the page, we see that at the very top here it says, 3:13 Learning Site Administration instead of Django Administration. 3:17 That's it. 3:21 See how easy that is? 3:23 You can do this with any of Django's base templates in the admin. 3:25 You just have to copy the template from the source code into your project and 3:29 put it in this admin directory under templates, 3:34 right there at the project level. 3:37 Then you can change all the places that say Django to say something else. 3:39
You need to sign up for Treehouse in order to download course files.Sign up