#100DaysOfCode in Python Transcripts
Chapter: Days 97-99: Building JSON APIs
Lecture: Adding the Flask basics

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, so this Flask is coming soon. Flask is coming now, let's do it. So we're going to import flask,
0:06 and down here, remember, you have to create the Flask app. And I'm going to use it like this, so we always see the full namespace of flask,
0:13 just so it's really clear what's going on here. And let's just build, like, a hello world, or welcome to our site, little view method here.
0:21 So let's call this index. And you have to add the app.route decorator and in here we're just going to put forward slash.
0:29 So that's going to tell it what to do, and then we'll just say return hello world. And just for good measure, just so we can keep track of this
0:37 in the future, 'cause we're going to run into issues, let's add a not found 404 handler, and we'll just return the page was not found. So that's great.
0:48 And then let's go down here and we'll actually have a main method, let's put that right at the top. That's my style. So we'll say app.run like so.
0:58 And let's even say debug=True. That's going to be really nice for us, we'll see why in a bit. And then we'll say down here, we'll do our little
1:06 main convention, that is in Python, and we'll run the main method if that's the case. Whew, okay, is it ready to run? Let's run our web app and see.
1:15 Whoa, success. We have something here. Click on it. Hello world, awesome, how about that. What if we go to abc?
1:25 Page was not found. Okay, so it looks like both the regular index and the not found stuff is working really well.
1:32 So this is cool, and just so you know, what this debug=True is it'll watch these files and see if you make a change and automatically reload it.
1:41 So let's go to hello world, three exclamation marks. Go over here, if I refresh. Automatically, I didn't have to do anything.
1:50 Because down here, you can see it detected a change in that file. Restarting, debugger is active. Beautiful. Okay, so, this is all really good,
1:58 we got our Flask up and running. But this doesn't feel very much like a JSON API method, does it?


Talk Python's Mastodon Michael Kennedy's Mastodon