Python for the .NET developer Transcripts
Chapter: Web frameworks
Lecture: Concept: Creating a Flask app
0:00 We've been working with our Flask app for a while
0:02 but lets review the main flow of what we have to do
0:05 to create, at least the server side Python code
0:08 bit of our Flask app.
0:10 So we're going to start out by defining an app instance.
0:13 This is a singleton for the entire application.
0:16 We create just one of them and it's a Flask class instance.
0:21 Then we're going to define an action or view method.
0:24 Here we have the guitar list that's going to show
0:26 all the guitars. It's going to accept a style.
0:28 Notice it has the app.route there.
0:31 So we're going to add the route decorator
0:33 to the guitar list method.
0:36 And we can pass in just static text to match
0:39 or if in angle brackets we can pass in variables
0:42 multiple ones if you want.
0:44 Here the method takes a style
0:46 and that route defines the style.
0:48 There's no coincidence that those two things go together.
0:50 Then we do our implementation.
0:52 And finally, we return a rendered template response
0:56 so we say we're going to render template.
0:57 Use the guitar.html input we're going to use
1:00 and it's probably based on the layout one.
1:03 And we pass the data, key=value
1:05 so guitars is the key and then the values the list
1:08 we also called guitars.
1:10 That's it, that's a pretty simple web app, isn't it?