Adding a CMS to Your Flask Web App Transcripts
Chapter: Routing for the CMS
Lecture: What is routing
0:00 in this chapter, we're gonna work on routing or rooting if you're a fan of
0:06 UK English and in routing. What you do is you specify different Urals or Euro
0:12 patterns with some replacements that map to different parts of your Web application. Traditionally, this is much more structured.
0:20 If, for example, in our Pipi I won, we say, if we're gonna go to a package slash package name that goes to the thing that shows the package.
0:28 But with CMS is, it's different. What we want to do is if we want to say anything,
0:33 anything you request from our side that's not handled by some other part, we would have a look at it and think about it and then either decide yes
0:41 that this euro represents a page and we'll go say to a database and pull back the information and show it to you. There might be no real page at all,
0:48 but conceptually there's a page. We want to look at that and decide that's the case. Or maybe not right.
0:53 They could make a request to something that we don't think is part of our site and we'll say no understanding.
0:58 Routing is really foundational. It's the thing that lets us get into the rest of the website and make this CMS idea happen. So what is right? Anyway,
1:09 let's do a quick, quick review of it Now, over here on the right, you can see I have two files to view Python files, and each of them have two methods.
1:19 The package views contains index and details and home views. Contains index, which is like Ford slash for our site and then about which is
1:26 you know, maybe slash about. I don't know what we've mapped it, too. So let's imagine that on the left we have a Web browser on the
1:33 right. We have a server that's set up something like this. A request is going to come in. The browser is gonna click a link or hit a book,
1:41 marker search or whatever to come up with trying to request slash project slash sequel alchemy
1:47 Question mark mode equals at it what that means in our sight. It's not super important, but what the goal of what we're gonna do is try
1:55 to figure out which of these functions on the right, if any should be called based on the rounding So when we create index,
2:03 we put an app dot router blueprint that route on the method as a decorator, and it has a euro in there in the index,
2:11 one on home is just slash so you can see that maps the home view stock index well does slash match This URL A came in as a pattern.
2:21 No, they're not even close to the same thing. So we're not going to call that one. We're going to go to the next registered Earl,
2:27 which is slash about this has been mapped to goto home views thought about also not a magic a slash project and slash about.
2:36 These are not the same things over in the package. One under the details we've said if something goes slash project slash some replaceable piece of
2:45 data. That's what this angle brackets mean there and we're gonna call it package, but it doesn't really matter what it's called.
2:52 Slash project slash some replaceable piece of data Does that match slash project slash sequel Commie
2:57 The query string question mark mode equals something is not factored into the routing that's sort of applied afterwards, So yes,
3:05 absolutely, it does slash project slash sleep, welcoming his slash project slash something.
3:10 So what's gonna happen is Flask is going to call package views dot details, but before does it's going to set up the request.
3:17 It's gonna go over here and safe. Last out requests dot org's is the query string, so it has a key of mode in a value of edit.
3:25 If there are more things in the query string, that dictionary would have more things. And then it's going to call package use,
3:30 dot details and pass in the pieces that we've said our variable elements in our route So we said, There's a package,
3:38 it's a string of dysfunction and it's gonna be obviously passed sequel Alchemy Right when Blast
3:44 called, Our function is going to set the value to seek welcome, eat and pre prepare the request. With the arguments set like this,
3:51 we're submitting a form it would have request stop form set with a bunch of the values from the forum and so on.
3:57 So this is how ratting works in general. We're gonna be ableto leverage this system to add a CMS type of capability that I
4:06 described that gets a chance to look at every euro That's not already handled by something Say here on the right in.
4:13 Decide if we're gonna return a page or tell them it doesn't exist. So understanding this flow of house routing works and how we can get in there and
4:21 work with it is super important as a foundational idea.