Python for the .NET developer Transcripts
Chapter: Web frameworks
Lecture: The filter buttons

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well we were hacking in the style here, but let's
0:05 be a little more specific about this for the moment.
0:07 Let's suppose we want to find a way to pass the style
0:12 over and let's actually go and add some buttons to make
0:14 that happen. I put a little thing about buttons here
0:17 and let me just put a few br.
0:20 Were going to have a proper style
0:21 in a minute that pushes these down but let's just go in here
0:23 and say we want to have some buttons.
0:28 And I already have some CSS style so I'll go ahead and
0:30 apply them here and some filters and then we're going to have
0:34 an a that has a class btn, and a class btn-dark.
0:39 Is it from Bootstrap and I want three of them
0:42 and I would really like
0:43 some new lines but y'know you get what you get right?
0:47 This would be all guitars, electric and acoustic guitars.
0:51 And then we need some URL's here so this'll be
0:53 /guitars/all, /guitars/electric
1:02 were just going to pass the style as part
1:03 of the Url here okay. And acoustic.
1:07 So this is going to be good
1:08 let's see what we got.
1:11 Here if I refresh this, oh nice these
1:13 buttons are looking good. Right?
1:16 Now you can see the Url is
1:17 goin up here but we're again getting this not found thing.
1:20 So the next thing we need to do is set up some routes in
1:23 ASP.NET and we see you have default routes. It's always
1:27 /controller/actionmethod and then an optional /id which
1:30 could be our all electric and acoustic.
1:33 We don't have that in Flask. You got to be super explicit.
1:36 It's sometimes annoying but sometimes nice.
1:39 Also we can just have another route, something that goes
1:42 here so we can put it in angle brackets and say style.
1:45 Now there's a warning, and what is the warning about?
1:52 So lets go over here and say that this is a string, it
1:55 gets past it like so.
1:56 And then it needs a default value because this right?
2:02 So were going to say by default its None, but if you pass a
2:04 style its whatever you passed over.
2:07 And now let's go and run this one more time
2:10 see what we got.
2:11 Okay here's our guitars, there's all guitars notice all of
2:14 them listed here.
2:16 If we ask for just electric, I'm sorry just acoustic
2:19 look at that!
2:20 It's filtered down to acoustic, electric, acoustic all.
2:24 So nice, so that was incredibly easy to add right?
2:27 We added this, we added this, we added a little type-hand
2:31 that was optional but makes our world better.
2:33 You can constrain these to be like integers and other stuff
2:36 but, this is just a string so there's no real constraints
2:39 upon it. And there we go, now were fully implementing this
2:42 like this is, this is done. This needs to go to the data-
2:45 base eventually and this template needs to do a lot more
2:48 work but from the actual implementation of the guitars
2:52 view-method, that is it.
2:54 That's pretty slick, right?