Adding a CMS to Your Flask Web App Transcripts
Chapter: Routing for the CMS
Lecture: Adding our 404 page

Login or purchase this course to watch this video and the rest of the course contents.
0:00 as you saw from those examples, having a fun and playful for four error page and you probably 500 from the server
0:07 crashes as well. But having one of those fund runs requires a little bit of design, a little bit of HTML,
0:13 a little bit of creativity. I've already done some of the work. Let me just show you what I have done here instead of having you watch me
0:19 do it. So I added a little bit of CSS styles. I've added an error page here, so just like all the other pages,
0:29 it used the layout. That means it's going to keep its header in its footer and all the other stuff that happens,
0:35 and except we're gonna have a little message that says we can't find it. And now there's this four or four error right here.
0:43 We dio static image and it's this broken set of boxes will talk about what that's about in just a second. I've already done those things,
0:53 and so our goal here is going to be to basically plug in this error handling
0:59 into our Web app, and we're gonna leverage those things that already exist. Good interviews and we're gonna have something.
1:06 Let's just copy this and paste it. That's easiest civil to say. Error views. And down here what we need We don't need the CMS.
1:15 This is gonna be errors. That name has to be unique working and not do a blueprint route. But let's put it error 404 here for three or three.
1:25 What do you think now for four? I want to put something up there. And then what we're gonna do is we're just gonna basically show a static page.
1:34 I want to say go here to flask and say Render template. I wouldn't give it based on the template folder when say, errors. Look how awesome PIJ arm is.
1:43 It's detecting the blueprint, and it's looking over there. Okay, on what we want is for a four, and we can give it an empty dictionary,
1:53 or we could actually just leave that blank. I don't think it needs it. And then what we want to do is we're gonna return that response now.
2:01 This might look like what you want to dio, but what you need to do is you need to communicate back to the Web browser
2:09 and maybe even more importantly, to search engines like No, no, no, This does not exist because by default it's going to return what
2:16 say called a 200 status code, Which means, Hey, everything's great. We don't think everything's great. So we can alter the response code by putting as
2:26 a second return value or, more accurately, creating a two bowl where the first thing is the response. And the second thing is the status good?
2:33 Not my favorite way of doing it, but so it is. It's also going to take an error argument.
2:39 We're not using error and notice that Pie Charm warns that it's not using gold thing
2:44 over here. So I thought what you can do is put an underscore to say Yeah, yeah, I know it takes a thing. I don't care about what that thing is.
2:51 Please, just make it work, Okay, this is close, but let's see where how far we've gotten here if we go back here was thes off,
3:00 click on help and know no better was wrong. Well, how do I have a flask? You know it's supposed to use this error here.
3:09 Well, it doesn't. So what Weaken Dio as we can go over here and use our blueprint just like before and register it. Careful, Careful. Careful here.
3:16 If you say air handler, what you would put is the status code or the exception to in this case we're handling,
3:24 not found, which is a 44 You would think this would work. Blueprint on air handler does not support for four and yet gives no warnings and no
3:33 errors. What you need, which is not obvious sometimes is app. You're a handler for 44 Okay,
3:39 with that in place, let's go register this just like we can before we're gonna have air use and let's put it was put home up here.
3:50 I have AP register. Blueprint. A reviews on Blueprint. Try this again. Over here. See? Their home page still works. I log in. Still works.
4:01 But what about help? Wait for it. Yes. The hairs are cool. Arab age four of or we just can't find that page.
4:10 Sorry. Maybe you should head back to the top of the site. Isn't that a better experience? And I think that fits a little bit with our
4:16 dynamic nature of our CMS and our pages. One more thing. What's the broken blocks about? Well, if this over here is the logo of the working Pipi,
4:26 I Well, this feels to me like broken pipe ei. So I came up with this little picture based on their logo.
4:32 Right? You guys can come up with whatever you want for your site, but knows we solve the footer down here. We still have the navigation, the design,
4:38 But it is a proper for four final thing. Go inspect element. Got a network, said it to Joe. Just HTML. And you dio, click again.
4:50 Notice. We're getting 404 for the document right there. That's super important. That tells things interact with the site.
4:58 No, this doesn't exist. And yet things like log in come back as a 200. Don't need to persist. Logs and slash comes isn't is 200 but help.
5:08 Comes is a 44 perfect. We have a beautiful and playful 44 page, and it conforms to Web standards communicating that it actually wasn't found there.


Talk Python's Mastodon Michael Kennedy's Mastodon