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

Talk Python's Mastodon Michael Kennedy's Mastodon