#100DaysOfWeb in Python Transcripts
Chapter: Days 1-4: Flask Intro
Lecture: Run your Flask app!
0:00 Okay, time to work on that demo.py file
0:03 so just head up one directory
0:05 back to our one Python Flask directory
0:09 and there's your demo.py file that you created.
0:12 Let's just Vim into that and all we really have to do
0:16 in this file, is we're telling Flask what to do
0:19 so when you run the Flask command to launch your app
0:23 which I'll show you straight after editing this
0:25 this is the file you point at
0:27 because this is what kicks it all off.
0:29 This is what tells it what package to use and so on.
0:32 So, all we have to do is go, whoops
0:36 from program, import app.
0:40 Now the reason this sounds confusing
0:42 is because we're importing app
0:44 and we've referenced that before in other places
0:47 so let me just walk you through it really quickly.
0:51 Save that. Let's just verify it.
0:55 Okay, so from program import app.
0:58 Now, this is talking to the __init__.py file.
1:04 So we have app in here.
1:07 What we're saying is, from our program package
1:11 import the app instance, or the app object of Flask
1:16 and then, from there, it's going to do this one
1:20 from program import routes and reference the routes.py file.
1:24 Alright? It just sort of goes through that tiered approach.
1:28 Now, we head back up. One last thing we need to do
1:31 before we actually run this program
1:33 is tell Flask, the Flask command, to use demo.py
1:39 and we do that through an environment variable.
1:42 Now, this environment variable is set differently
1:46 in Windows from macOS or Linux.
1:49 If you're using any sort of Unix environment
1:52 you'd be used to using this method.
1:54 So, export Flask underscore app
1:58 and then we want to talk to the demo.py file
2:02 and that works. Now, in Windows, we can't do that
2:05 because you can't set environment variables using export.
2:09 We have you use the actual set command.
2:11 So, set FLASK_APP=demo.py
2:16 and then we go. So, if you're using Mac, use export
2:19 or if you're using macOS or Unix, whatever
2:22 and if you're using Windows, use the set command.
2:25 Now, all we have to do, is flask run.
2:33 Okay, and you can see we are running
2:35 our website on 127.0.0.1.
2:38 That's localhost, port 5000.
2:41 So, let's bring up a web browser and check that out.
2:45 So, I've just opened up a web browser here.
2:47 This is Google Chrome in incognito mode
2:49 and I've just punched in the URL or the IP address
2:53 127.0.0.1:5000, and that's it.
2:58 We see the returned string that we had
3:01 in our routes.py file, okay?
3:04 In the background, we see the actual timestamp.
3:08 We see the address that we're talking to.
3:11 We see the URLs that were requested.
3:14 Just ignore this one. This is a remnant from a bookmark I had in there
3:18 and that's it. There's our very first Flask app.
3:22 What I'd like you to do now is just have a play around
3:24 with the routes.py file.
3:26 Add in some other return values.
3:28 Do whatever you want to play with
3:30 but this should be long enough to get you through today
3:33 and possibly a second day
3:34 depending on how much time this took you.
3:36 Just have a play, have some fun
3:38 and let's move on to the next video.