The Adder1:33 with Kenneth Love
Making your apps more friendly and adaptable is a great idea. How did you do on the challenge of adding more routes to your view? Here's my solution!
Adding multiple routes to a single view is a great way to allow the route's arguments to fit within some constraints, but still be real world.
Well, did you do it? 0:00 Let's look at how I solved the problem of catching both types of numbers. 0:01 All right, so just to remind you, if we try going to our thing and 0:04 we have something that's not, not an imager, 0:10 then it errors because it can't convert that into a number. 0:14 But let's see about turning this into something that takes ints, 0:18 floats, you know, either one of those. 0:21 Okay. 0:24 So, what do we have? 0:25 Well, first of all, 0:26 we have this app route where we have ints and, you know, they're both ints. 0:27 So, let's let's duplicate this and let's make them both floats. 0:31 All right, and 0:38 then our other option would be that number one is an int and number two's a float. 0:39 Or that number one is a float and number two is an int, right? 0:45 So we have int int, float float, int float, and a float int. 0:49 Let's let's give these a test. 0:53 All right. So first of all, let's do 2.5 plus 5. 0:54 7.5, great. 0:58 2.5 plus 5.5. 1:01 8.0, great. 1:03 [BLANK_AUDIO] 1:05 And there we go. 1:08 All right, so, and 1:10 let's just, let's make sure that it still works with just two ints, and it does. 1:11 All right, four routes on one view. 1:16 That's kind of crazy, but that should cover everything. 1:18 Creating routes for your views is a major part of working with basic Flask, but 1:22 there's actually a whole lot more that we can do with this framework. 1:26 In our next stage, 1:29 we'll take a look at rendering templates and serving static files. 1:29
You need to sign up for Treehouse in order to download course files.Sign up