Adding a CMS to Your Flask 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 began talking about how we might create this CMS idea inside of our data driven Web app inside of our flask app by talking about routing.
0:10
And that's because normally what we do in routing, as we say, we have these certain data driven,
0:16
structured parts of our site and they look like this example, Ural, or that example your l and what we needed to do.
0:23
It's somehow fit in at the very end of that. Some way to say before you say that is not found before you say it's not
0:31
part of our site, let me have a look at it. Use a little bit of Python code and decide if that represents a virtual conceptual page
0:38
or redirect in our CMS, and then we'll tell you whether or not it's found So at the heart of this is routing.
0:45
So let's review routing in general and then how we created our CMS with it.
0:49
So remember, a request comes in looking something like this in our Pipi I example
0:54
it might be slash project slash sequel Commie with a query string question mark mode equals edit and to find over on the right.
1:02
Here are our various views. So we have some packages one for index, which lists all of them and one for details on given one of them as well
1:11
Some home views index, which is just bored slash the main site or possibly
1:16
some kind of about Paige. We've registered some blueprint routes and said for the index method in home views, we want to map that,
1:25
too slash ford slash That's the root of our website. If you go to the Visit Server, this is what you get. So the question is,
1:33
does slash project slash sequel Commie Ignoring the query string for the moment. Does that apply? Does that match slash No, it doesn't. We also said,
1:41
if you go to slash about that, goes to this home views about method, not a match slash project slash about those were not the same thing.
1:50
Then we had a more interesting route slash project slash angle bracket package and that angle
1:56
bracket package thing that's like a variable place where the name of the variable is package and the value is whatever's in the oral.
2:02
And so does that match slash project slash seek walk me? Yes, yes, it does. So flask is gonna call this function,
2:09
Gonna set up the request and say the our eggs are what the query string are here. And then it's going to call our details function.
2:17
And the details function has toe have parameters in the method there to take. All the variables that are in the URL are the route.
2:25
So here we say, there's a angle bracket package so you can see the details takes a package. And right now we're saying it's a string.
2:32
So when the functions called in this particular example, package has the value of sequel alchemy. All right, so this is routing in general,
2:40
and normally we need to find these routes. It says, Well, if there's no match here, we're just gonna say that page is not found.
2:46
It doesn't exist for a four. Remember, what we want to do is extend this. So the way we are going to do this that we say we want toe handle
2:54
arbitrary requests into our flats. Web app, slash sums last arbitrary slash URL and in that package before it could have a variable
3:03
value like sequel alchemy or flask. But it couldn't be sequel coming slash details or something like that, right? It can't have a slash in it,
3:11
but we got to do a little extra work to capture these. Full your nails like this. The way we do that is we say that the
3:18
girl is not a string or an integer or anything like that, but it's a path. So here we're adding around and it's got a variable called
3:26
full euro. But we're seeing it's type path, and that's the key that will capture everything,
3:32
at least everything from path on Word that you could have some stuff in front of this as well and have some variations here.
3:39
But this path thing means capture everything to the right. No matter what shape or form it takes in the morning. Pass it in. After that,
3:48
it's pretty straightforward. We're just gonna go get the page or whatever it is we're
3:51
looking for from the database and then show it or determine its A re direct and
3:57
redirect them right? So the actual context here that we've got to use the thing we do is just this path.
4:03
It's not that super complicated, as we saw much of what makes this an interesting project is making the management admin side powerful and interesting.
4:13
Not so much capturing. But this is the way that we get into to start capturing the quest. The request to build this idea of a CMS.