Python for .NET Developers Transcripts
Chapter: Web frameworks
Lecture: Concept: Creating a Flask app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We've been working with our Flask app for a while but lets review the main flow of what we have to do to create, at least the server side Python code
0:09 bit of our Flask app. So we're going to start out by defining an app instance. This is a singleton for the entire application.
0:17 We create just one of them and it's a Flask class instance. Then we're going to define an action or view method.
0:25 Here we have the guitar list that's going to show all the guitars. It's going to accept a style. Notice it has the app.route there.
0:32 So we're going to add the route decorator to the guitar list method. And we can pass in just static text to match
0:40 or if in angle brackets we can pass in variables multiple ones if you want. Here the method takes a style and that route defines the style.
0:49 There's no coincidence that those two things go together. Then we do our implementation. And finally, we return a rendered template response
0:57 so we say we're going to render template. Use the guitar.html input we're going to use and it's probably based on the layout one.
1:04 And we pass the data, key=value so guitars is the key and then the values the list we also called guitars.
1:11 That's it, that's a pretty simple web app, isn't it?


Talk Python's Mastodon Michael Kennedy's Mastodon