Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Routing for the CMS
Lecture: Examining the existing routes

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before we start adding our CMS content and our CMS routes to our website, let's just quickly review the routes that are already in place.
0:09 Now I like to organize my projects more than is specified by various frameworks.
0:16 So here you can see in our main method, we've got our includes, our sublibraries, optional libraries that get included, like chameleon.
0:23 Over here, we've got our database initialization and then our routing. In newer versions of Pyramid, if you create a new project,
0:31 it'll put this routing into a separate folder, and then include it kind of like this.
0:35 That's fine, but I don't think we really I like it just this way as well. It's totally good.
0:41 So down here, let's look at what we got. There's quite a bit going on, isn't there? So we have the static route here, and it's at one hour.
0:50 Just give you a sense of my real websites. It's at a year,
0:53 and we do some techniques to make sure the URL changes if underlying content that shouldn't be cached any more changes.
0:59 So this is kinda gonna small, but that's that's okay.
1:02 Here we have, I like to group them by controller you could tell already I like to use a lot of organization here.
1:08 So here we have 'home', which has various methods like 'home' and 'about', and our templates have 'home' and 'about'
1:13 our view models have something like that about page doesn't have a view model, right?
1:18 So same thing here we have home or have some names 'home' and '/about'. Slash in about. And let's go over here and look how that ties back.
1:27 So over here we have our 'home index' and then our 'home about'. We could just call it 'index' and 'about', but I decided to call it this.
1:33 And you could see the route name right here, 'home' and 'about'.
1:36 And if for some reason, this was different, like if I put a '2' there and try to run it,
1:41 It's going to crash and say we looked for a route called 'about2'. Apparently in the entire 'init_route' method,
1:48 The whole startup of the app, You didn't ever register a route called 'about2'
1:52 So, that's how these tie together. You can see that it's pretty picky that those were actually valid. What you put there.
1:58 We also happen to be saying we're using this. These various templates here and then returning a dictionary to those templates.
2:05 Just standard pyramid stuff. So let's go back and look at some more. We have the package controller.
2:10 This is for the various packages, So if we pull this up, you'll recall. We go and click on one of these.
2:19 notice it's 'project/aws-cli'. If this was sqlalchemy, is that in our short database? It is.
2:25 So you can see it pulls it up to this bit right here is passed over to that method. And the way it's done is, we say it's '/project/<SOME VARIABLE>'.
2:35 We'll grab that we call it 'package_name'. Now, One thing that's annoying about Pyramid is whether or not the slashes on the end matters.
2:43 So I've added a second route to say if they put the slash, same action, do the same thing. Here you can see one that has a constraint.
2:51 So this actually can appear first because it's the only one with numbers in the front,
2:55 so I could go over here and put '1' and see the most popular package
2:59 Where as the website doesn't really pull it back It just says the 1st, 2nd, 6th, and so on.
3:06 But it's not catching things like 'about' because of this constraint here. Okay, so we got that we got a package, details, some release details.
3:15 And then down here, we have our account for log in, and register, and so on. One other thing let's look at the account bit right here
3:23 that you work with and specifying a matching these routes. I talked about the URL matching the pattern. That's true but also the http verb.
3:31 Are you just doing a request to a page which would be a GET, or are you submitting a form back to that page which would be a POST.
3:37 So we can also distinguish between these two methods here on whether it's a GET or a POST, in addition to having the same route.
3:46 I guess that will come up somewhere as we work on our CMS. Technically, the CMS as a consumer of it will probably be only GET.
3:53 As we work on the admin section to edit our pages and whatnot, of course, we're gonna need a have both of these in place.
4:00 All right, well, that's pretty much it for the routing that we have in place here I think we're, yeah. I think we're pretty much good


Talk Python's Mastodon Michael Kennedy's Mastodon