Python for .NET Developers Transcripts
Chapter: Web frameworks
Lecture: Exploring the ASP.NET Guitary

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before we start writing the Python the Flask version of guitar, of course we have a C# version, course they built you a C# version.
0:09 And why did I build it in? Well, ASP.NET Core, of course. So let's just quickly poke around this ASP.NET web app. Maybe you're familiar with ASP.NET
0:19 but just because you're a C# developer doesn't mean you've done web development over here. So I'll try to give you a quick fly over
0:24 but again this is not the main focus. The main focus is rebuilding the equivalent Pythonic web version the proper idomatic version
0:33 of the Python web app. But nonetheless let's understand where we're coming from. So let's start with the controller that's probably
0:40 where you want to start with an MVC framework ASP.NET. So this app turns out to be pretty simple. We've got a little dependency injection thing that
0:48 we're actually kind of ignoring going on here but then we have a couple of methods basically only two action methods and then this Error method which
0:57 ideally we don't hit I guess, but maybe we will. So this is the home view, that is that's this view right here with the sort of landing page
1:06 and we will rock, that sort if thing. And then we have the guitars and over here we're using view models. Really nice design pattern that I love.
1:16 We're going to create one of these view models and pass it off to the view. Now, this is for the guitars and we're going to say the
1:23 style is either all or acoustic or it's electric, right? That's the part here where we're looking the guitars and we're switching between these three.
1:33 So we're pulling that out, it's being passed its part of the URL right up here. guitars/acoustic. So guitars, acoustic and it's being passed over here
1:43 going to the data base and filtering it. So I guess a good place to go from there would be like here. So here's our view model it has some
1:52 basically the input data, and then it has the guitars. We have a CatalogService like our guitar catalog I guess.
1:59 And it can go and get all the guitars based on style. Let's go check that out. Now here we have our turns a guitar array pass in a shop
2:09 style could be empty, like I said this is static data for now it's going to be in the database soon. If there's no filter just give all
2:17 otherwise we're going to do a link to objects query for now. This is going to be a LINQ to Entity Framework later.
2:24 Going to say give me all the guitars with the style such and such give me that guitar back. And I guess the last major thing to look at is just
2:31 the views down here to round it out let me stop it so you can get this out of the way. When we go to our controller here and we call the
2:42 guitar method with the right stuff and we say return view with this view model. What it does is it goes to this Razor template over here.
2:48 And this Razor template of course shares this overall layout that we're using. So what we're going to do is we're going to say that view
2:56 model is this that we come in statically programing gets it. Our little top bit this is just a padding for the linment of around the navigation.
3:05 We have our custom guitars and these are the buttons. So if we were over here those are the buttons you
3:11 can click there, and then for each guitar we're going to spit out a little div that we're going to float, not float
3:18 we're going to put as an inline block and it has an image which is the guitar image, the guitar name and the guitar price.
3:25 That's it. That's right here the image, the name and the price. I guess you could probably use a dollar sign, something like that right there.
3:35 Not really required but we'll go ahead and throw it in there for the future. And that more or less is the web application, round one.
3:43 Later when we get to doing something more impressive with the database, but for now this is the web app
3:50 that we're starting from in C# and we're going to rebuild in Python and Flask.


Talk Python's Mastodon Michael Kennedy's Mastodon