Adding a CMS to Your Flask Web App Transcripts
Chapter: Routing for the CMS
Lecture: The cms_service

Login or purchase this course to watch this video and the rest of the course contents.
0:00 remember when we did our quick overview of our Web application? We said, we have this idea of these services,
0:06 that group working with different kinds of data, whether that comes from Web services or the database or whatever.
0:12 And we have one for working with package data and one for user data. Well, guess what? We should have won four working with CMS type of data
0:20 as well, either from a read only perspective like we have right here or from the admin side of things like create a CMS page or create a redirect.
0:30 So we're gonna follow the same pattern and say we have a CMS service here is
0:36 just gonna have a couple of functions to start to get page and this could have a shot of base. Well,
0:45 the string And for now it's going to return Either a dictionary or nothing's will say an optional dicked like this and this.
0:57 We could put more details about what's contained within the dictionary, but this is good enough for now. And let's have one for redirect.
1:08 Yeah, that'll work. Well, where we're going to get this data in the long term,
1:13 we're gonna put it into a database like post dress or something like that or mongo db We're gonna make a query over to the database,
1:19 but I don't want to worry about that now. I don't want to work with the complications of that right now, so we're gonna get to that in a little bit.
1:26 But for now, you look over in this DB section. I have some very fancy. Did you know that we can use this bake data It has some pages. There has,
1:35 like a euro like a thing. And then it has a title and contents, right? Here's the donate and here's some contents about donate.
1:44 Also, we have redirects, which has a little short You're ill as well as
1:50 the destination. So let's go over here and we're going to say something like this If not base, you're also if they pass nothing or not base where all
2:02 that strip. So if you take away all the like a white space, whatever. If there's nothing there, we're gonna return. None also return.
2:12 This may be safer about my saying none and then we'll go over here. I'll say based your all equals base year old dot strip.
2:20 Take away white space on the end and make sure it's a little case because we
2:23 don't want to keep track whether they say Capital C courses or Capital C company versus
2:28 Lower Case C company all the same to us and then we're just going Teoh say Page equals big data get and we'll get rid of this in a little bit.
2:39 But But it here and get the base euro and return that like so that's pretty straightforward. And you know what? It is incredibly similar down here.
2:51 So it's just to rob that. And this, instead of be pages, is gonna be redirect and calling That page is kind of misleading.
2:58 Let's do a rename and PyCharm. A call that a redirect like So you All right, Let's go and try to use this year.
3:10 I guess we can leave that comment for a minute. So here will say Page equals CMS service and let pie Charm import that at the
3:19 top. Thank you, and let's go in here and say, Get page full Euro. I'll say if there is a page that they gave us
3:27 we'll get just gonna return something like this year. Well, say title is here on tents. Go here and let's a quick peek back.
3:45 So the titles Lower case title in the contest is lower. Case contents. Those to be page not get title is get on dense.
3:57 If we don't have this is going to return, we'll ask, not abort statuses or afford just for a minute.
4:06 Let's stick with that. So over here and went to a quick test. I'll try. Our featured projects doesn't exist borough for But I think the donate one
4:17 did. Yeah. I don't donate to the psf. Did you know you can actually use their donation link right there?
4:24 Where did that come from? That came from the fake data right here It went and found that entry. And so it returned that tour view method RV method,
4:34 grabbed the title in the content and then showed that back in the email page Cool right? We could ask for donate.
4:42 We could also ask for a company slash history or employees and those are the three things we can ask for. So we could come here and try this.
4:50 We get that right, that's working. And we could have imprint. Oy, ease. Let me get this,
4:55 but not not employees. Singular is that's not something in our big data database. Cool Right to the other thing.
5:03 Weaken Dio Why we're here. It's Let's go ahead and try on a redirect thing We'll do a lot more of this in the very next chapter.
5:15 I will say, if reader act, turn off last Ott redirect to redirect and I get It's your own.
5:26 Let's double check. That's true as we have slash courses short euro, which is supposed to go toe that euro,
5:32 which, yes, is it or slash bites goes a Python bites. Let's dry that here is well, so this still works. This should still for a four.
5:47 Our website should still be working and it does going here, for example. But if we go over here and we say slash courses,
5:55 what's gonna happen? Well, it should find it not as a page, but is a redirect and send us over to training dot talk by Thunder FM. Try it. Oh, yeah,
6:06 How about that senses to the courses over there. If we do slash and bites, it's just send us to Python bites.
6:13 And if we do talk would say may wouldn't go to talk about it on. Is it there? Nope. Not found. It's not a page that redirect so not found.
6:23 Cool. Well, that was not a ton of work, was it? And I guess more self explanatory. Weaken. Drop that. Now.
6:30 Check for a page check for redirect one of those we're gonna show them otherwise for
6:35 four. Well, this might seem like we're basically done like there's actually a whole lot more to this course that we're gonna be working on.
6:43 We're just getting started. You might look at this and say, How much more is there really?
6:48 Well, where we're going is we're gonna have a whole awesome admin section with, like, rich editors and softer create manage these pages.
6:56 We're gonna have ways to show them. So they appear as if they're part of our website and similarly admin section for this
7:03 There's a lot of cool stuff that we're gonna be doing, and then on top of that performance and different types of formats, And so is it a lot to do,
7:10 But in terms of this function, not a lot to do. It's actually pretty straightforward, isn't it? Super cool. So we've got our basis of our CMS built.
7:20 So every request that the CMS you gotta process a page or redirect is going to flow through this one simple little place here,
7:29 and it's because we said that this is a variable and it is a path type


Talk Python's Mastodon Michael Kennedy's Mastodon