#100DaysOfWeb in Python Transcripts
Chapter: Days 65-68: Heroku and Python Platform-as-a-Service
Lecture: Setting up the local app and Heroku environment

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Hopefully you have installed Heroku CLI successfully.
0:04 Once you've done that we can get cracking
0:07 on the application.
0:09 The first thing you need to do is actually log into Heroku
0:12 and that's using the account details you set up
0:14 in the earlier video.
0:16 If you are to do that through Commander
0:19 which is the app I'm using here
0:21 you actually won't see the prompt.
0:23 So, just to demo quickly
0:26 if you do Heroku login from the command line
0:30 you should see a prompt like this.
0:32 Enter your Heroku credentials.
0:34 So the first thing it asks you is your email
0:37 and then your password. On Commander here
0:42 I actually don't see that. So Heroku, login
0:48 and I simply just get a blank prompt there.
0:50 It doesn't actually show the word email.
0:52 Obviously I had to show you that for demonstration purposes.
0:56 What I'd like you to do is login.
0:57 I'll do that quickly and I've now logged in.
1:00 On your side if you're not using Commander
1:03 you should see a message that says
1:04 logged-in as, and then your email address.
1:08 All right the next thing we need to do
1:10 is we actually need to choose a directory
1:13 to, I guess, have our app in.
1:17 We need to get some code ready and then push it off
1:20 to the Heroku servers to run in the Cloud.
1:23 Now I've created a quick directory here
1:26 in my 100DaysOfWeb folder
1:28 and in here is a very very basic Flask app.
1:32 I will quickly show you.
1:34 You are welcome to just copy this off the GitHub Repo
1:38 app.py is a single file Flask app.
1:41 This is different to everything we've covered before
1:44 where we were using the larger scalable method.
1:47 This is again just for demonstrative purposes.
1:50 We have Flask imported there.
1:53 We have the app being defined.
1:55 We have an index route created and we just run it.
1:59 Okay, and that's it.
2:01 We then have a templates folder
2:04 with an index.html file
2:07 and simply in there we have a title
2:09 and h1 header that says my test Heroku index page.
2:14 That's all we want. I'm not getting complicated
2:17 because we want to keep this simple.
2:20 We're focusing on the actual deployment
2:23 The virtual environment is here.
2:24 I have not installed anything yet.
2:27 The only dependency we need
2:28 for this script to run locally is Flask.
2:33 So we will install that
2:36 and as I alluded to, that is to run locally.
2:39 So lets clear that out.
2:40 If we want to run this on the Heroku servers
2:43 we actually need a little more.
2:45 What we need to install is a Python Web Server
2:49 that is designed for UNIX based operating systems
2:53 and this is what Heroku runs on their end.
2:55 So for Flask to run
2:57 we need to install the web server
2:59 and the web server that we're going to install
3:02 is called Gunicorn. Okay?
3:06 So we'll go pip install gunicorn.
3:15 and now that that's installed
3:17 we simply just need to pipe everything
3:20 into our requirements.txt file, like we normally do.
3:24 What Heroku does is
3:26 it will consult that requirements.txt file
3:30 and on the server end
3:32 will then install all of the dependencies
3:35 that you need to run your application.
3:37 So we'll do pip that's not it
3:40 pip freeze into requirements.txt.
3:47 And if we kept that file
3:49 we have everything required for Flask
3:52 and we have Gunicorn.
3:54 Now, we are ready to start pushing some code.
3:56 So to do that we need to actually
3:59 initialize our directory as a Git repository
4:02 and we can simply do that by just doing Git init.
4:07 So let's deactivate our virtual environment
4:09 and store a Git init in this folder.
4:12 and now that that's initialized
4:14 we can do an ls -al.
4:16 You see we have a .git file there
4:19 so this is all ready to go.
4:21 And this will make sure
4:22 that this folder itself is recognized as its own repository.
4:27 And with our directory initialized as it Git Repo
4:31 we are now free to create our Heroku app
4:34 which we will do in the next video.