Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Course conclusion
Lecture: Review: CMS routing

Login or purchase this course to watch this video and the rest of the course contents.
0:00 we started out our exploration of adding the CMS functionality by talking about routing.
0:05 And the reason was it's essential that we find a way to get access to every single request that didn't correctly get processed in our sight.
0:14 If we slapped, asked for looking like slash packages slash seek welcome me. Well, the data driven side of that would go and grab it and process it.
0:22 But what if they ask for some other things like slash help?
0:26 If that wasn't already there, normally would just the Web framework pyramid would return a 44 and say, Too bad that didn't work.
0:34 What we want to do is look at that and say, Hold on. Is there actually something in the database?
0:38 Virtually we conceptually think of as a page, even though it's not technically in the site that we wanna return back to them. So that was routing.
0:45 Let's just review writing really quick in general. So we're gonna process that http get requests.
0:51 This is like clicking on a link to a euro or something. And this one is to slash project slash sequel Commie on the right.
0:58 We've got four view methods broken into two different vials. We've got some euros or routes associate with them.
1:06 So we said Slash home, that's going to go to our just slash. That's gonna goto home dot indexes going to call that function and do whatever that does.
1:15 So the system asked us slash Project slash sequel could be matched that the answer is no slash about. That's another registered one.
1:22 Also not a match slash project. Early bracket flash package.
1:26 So the curly braces mean here's a very well, it could be anything and yes, in fact, that does match. So your meds going to set up this match dicked?
1:35 It's going to say it's got different things that matched in the Ural in particular, where we have the variable package, its value is now seek.
1:42 Welcome me and then it's going to call the details function.
1:45 Passing this requested we can process it and tell them about this page that they requested.
1:51 Now setting up one of these special CMS routes, as I described, is a little bit different in our previous example where he had curly bracket package, it couldn't be slash sequel alchemy slash help or slash anything.
2:04 The flash can't appear there right It's not a general thing.
2:08 It's like, Well, there's slash project slash a single value What we need with our CMS world to say, give us everything.
2:15 And the trick to do that in Pyramid is to put this star that star sub path.
2:19 The star says match everything after this, not just a single value between the slashes.
2:27 And once we set this up, we can define a page method that's going to capture every request and then try to render a page here.
2:33 So we're going to say, first, get the request stop Mastic, and we're gonna get this sub path here.
2:39 The thing is that some path actually comes back as a list of things. Strings separated by those Ford slash it.
2:45 So if it was slash project slash sick welcome me, it would be a list of two things. One being project next string being sequel. Capi.
2:52 Did it work with that in our database?
2:54 We're gonna turn that back into something separated by slashes, and then we use our little seem a service to go talk to the database and get the page back, and then we just return that back to the page.
3:03 You were not really checking that case. The patient might not exist, but this gives you the general idea of how it works. Remember this route.
3:11 Appear this config dot Add route. It matches everything. The system will stop looking for other matches. Sooners that find something that is a match.
3:19 So it's very important that this line this config dot add routes. He mess that this goes at the very end of all the routing set up.
3:27 Because if you put it somewhere before then gonna be in trouble, that's not gonna work with anything below that, right? So do keep that in mind.


Talk Python's Mastodon Michael Kennedy's Mastodon