Adding a CMS to Your Flask Web App Transcripts
Chapter: Routing for the CMS
Lecture: Adding THE cms route

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well, we've talked about this CMS around for a while, and if you look at all the stuff happening over here, we have a bunch of different things.
0:08 There's all these different routes and methods and Ural patterns and what not that we're doing and what's ironic or what we're doing in this course,
0:18 the entirety of this concept of the CMS. We just need one girl. That's it. It's going to catch everything, and we have to decide what to do there.
0:30 Now, technically, we're also gonna have an admin section so that we can go and edit our site, live in the database and things like that.
0:38 So that'll technically take a few more you or else. But as far as the seam that's concerned is concerned, it's really just one. You're l.
0:46 But let's go in and do that nonetheless. Over here we have our views. We're gonna have a new I've on file and let's call it CMS views.
0:57 And in here we're going to need to go in, create a blueprint. Let's just grab that little bit from right there.
1:04 Make sure we import flask with out of the top now packages. No, CMS, yeah, that's what we're gonna call it.
1:11 You would have a function, and this is gonna be Just call it. See mass request. So this function is going to handle whenever there is a request
1:22 to the CMS. It's no matter what it is, even if it doesn't exist, it's going to call this function and then we're gonna
1:29 decide. So let's just have it first. Say hello, CMS Kinda like hello world. But for the CMS, after this to work, we have to give it some kind of euros.
1:42 Will say I'm blueprint dot route And then what is the rule gonna be? Well, let's say we want this to be a variable because obviously it's gonna be
1:53 a variable. And let's just say it's the full girl now, Sam, morning. You're not having that is not going to write it for us
2:02 But you're not adding that over here. Well, now we've added this. This maybe is OK. Well,
2:09 it's not gonna be enough, but let's just see that That's the case first. So let's go over here. We import our CMAs views and,
2:19 like our little comment, says, where to go down here and register the blueprint so Let's run it and see if
2:27 it works. I closed the other app that was running on the same five years or six. Port. Also, there is some weird CSS class that got in somewhere,
2:37 so that's what that pattern was about. It's all better now, so let's suppose we want to be able and get things like slash Donate. Oh yes,
2:47 our CMS is now working. Remember that failed or featured projects? Oh, that one doesn't work. Let's try help. Help? Yes,
2:55 help works What's different between help donate and featured projects.
2:59 While these have a slash something and this one has a slash something Slash something.
3:07 Let's make it a little bit more clear if we come over here and we say it's an f string. So you requested for your URL and we run that again
3:18 This doesn't work, but let's try donate you requested. Donate. We could make it even a little better if we put like that.
3:29 Have a go now it's slash donate. The problem is like I said before, though that only matches like this bit.
3:36 What about the rest? What about the rest of it? There is part well, what we want to do.
3:43 I mean, I guess we could have a whole bunch of complicated ones like level one, level 2/3. But what we can do with flask,
3:50 remember, we could say into to make that an integer. We can also say this is a path in the path. One is what we're looking for.
3:58 So let's save that should see the bottom. It just restarted itself. Let's see if our donate works. Yes, you requested slash Donate.
4:08 But what about featured projects who? Look at that. You requested blast featured slash projects. And this could be slash. Anything?
4:23 Anything we want. It doesn't matter. It doesn't matter what we're requesting. Anything on the site is now good.
4:40 Okay, It's now good, obviously. So the way we set it up is stuff that we had before still works so we could go over here. We're gonna go log in.
4:50 We could go to the aws cli We could go to register all those things, but stuff that didn't exist like help donate.
5:01 I help. You're back. Here are featured projects or anything else we type. Every bit of that is now coming into this function.
5:10 Look how simple that is. So what do we have to do to make this
5:13 meaningful To make this actually do something to add this cool CMS capability to our website Well, what we need to do is we need to first check if the
5:26 URL or will see it like this matches some page or redirect. We're gonna have to things we can do.
5:34 Want to show a page? The other one is Have a short girl that will take you to somewhere else much farther away,
5:40 as you'll see. So we're going to check whether it matches either a page or redirect. if it does great. If it doesn't, they were going to say sorry.
5:50 No page found and basically do what we were doing before just giving them a 44 But Glass was doing it for us on us.


Talk Python's Mastodon Michael Kennedy's Mastodon