Django: Getting Started Transcripts
Chapter: HTML Templates
Lecture: Registering new 'home' URLs

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Remember that to display something, you have to map the URL to a view. In the previous chapter, I showed you how to use the main mapping file in the
0:08 inner Alexandria directory. Here, I'm going to put some URLs together for just this app. Let me create home URLs.py.
0:22 This file is structured similarly to the main one in Alexandria. The key part here is the URL patterns value being a list of mappings for the app.
0:44 I've added a URL called sample and associated it with the sample view I just wrote.
0:51 This file on its own isn't enough Django doesn't know to look for it. It is good practice to keep URLs in an app together,
0:59 but you still have to register them all. Let's do that now. I'm going to open up the inner Alexandria URLs.py file
1:10 and now I'll add all of the child URLs from the home map. You do that by using the include function, note that isn't in the imports from the stub.
1:21 So I have to add it. Now I'll register all the URLs in the home app under the home base URL. The include function takes the name of an app's URLs file.
1:41 The result will be any sub URL defined in home.URLs will be included under /home than its own URL.
1:51 For example, the sample view I just mapped will end up at /home /sample with that saved, let's go check it out.


Talk Python's Mastodon Michael Kennedy's Mastodon