Python for .NET Developers 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 be a little more specific about this for the moment.
0:08 Let's suppose we want to find a way to pass the style over and let's actually go and add some buttons to make
0:15 that happen. I put a little thing about buttons here and let me just put a few br. Were going to have a proper style
0:22 in a minute that pushes these down but let's just go in here and say we want to have some buttons.
0:29 And I already have some CSS style so I'll go ahead and apply them here and some filters and then we're going to have
0:35 an a that has a class btn, and a class btn-dark. Is it from Bootstrap and I want three of them and I would really like
0:44 some new lines but y'know you get what you get right? This would be all guitars, electric and acoustic guitars.
0:52 And then we need some URL's here so this'll be /guitars/all, /guitars/electric were just going to pass the style as part
1:04 of the Url here okay. And acoustic. So this is going to be good let's see what we got. Here if I refresh this, oh nice these
1:14 buttons are looking good. Right? Now you can see the Url is goin up here but we're again getting this not found thing.
1:21 So the next thing we need to do is set up some routes in ASP.NET and we see you have default routes. It's always
1:28 /controller/actionmethod and then an optional /id which could be our all electric and acoustic.
1:34 We don't have that in Flask. You got to be super explicit. It's sometimes annoying but sometimes nice.
1:40 Also we can just have another route, something that goes here so we can put it in angle brackets and say style.
1:46 Now there's a warning, and what is the warning about? So lets go over here and say that this is a string, it gets past it like so.
1:57 And then it needs a default value because this right? So were going to say by default its None, but if you pass a style its whatever you passed over.
2:08 And now let's go and run this one more time see what we got. Okay here's our guitars, there's all guitars notice all of them listed here.
2:17 If we ask for just electric, I'm sorry just acoustic look at that! It's filtered down to acoustic, electric, acoustic all.
2:25 So nice, so that was incredibly easy to add right? We added this, we added this, we added a little type-hand
2:32 that was optional but makes our world better. You can constrain these to be like integers and other stuff
2:37 but, this is just a string so there's no real constraints upon it. And there we go, now were fully implementing this
2:43 like this is, this is done. This needs to go to the data- base eventually and this template needs to do a lot more
2:49 work but from the actual implementation of the guitars view-method, that is it. That's pretty slick, right?

Talk Python's Mastodon Michael Kennedy's Mastodon