How to Deploy a Flask App to Heroku | Flask Heroku Deployment

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back in this video i'll be going over how to deploy a python flask app onto heroku and for those of you that don't know what heroku is heroku is a platform where we can host in order to get started you'll need your flask app a github repository with the app and a heroku account so go over to heroku.com and if you don't have an account sign up for one right here and it's free to sign up also and once you've signed up you're going to need to install the heroku cli which stands for command line interface and we're going to be using the heroku cli to deploy our app so to install the heroku cli once you've signed up you're just going to search for heroku cli on the web and then the first link that pops up right here devcenter.heroku.com article slash heroku hyphen cli go down and then install it from here depending on your operating system and once you have installed the cli you want to go to your app directory in your terminal and then run a few commands so in order to deploy with heroku we're going to need to install gunnacorn with pips so just do pip or pip 3 depending on your operating system and then just type in install gunacorn and this will install a gun accord package and since i already have it installed it says requirement already satisfied then you're just going to do pip 3 or pip depending on your operating system again freeze and a greater than sign requirements dot txt and in case you were wondering what this pip3 freeze command does this will basically take a list of all the packages that you have installed with pip and then freeze them into one file which is this requirements.txt right here all right so next we need to create something called a proc file and a profile is basically a file that heroku uses in order to deploy our app so in order to create the proc file we're just going to do touch profile and make sure it has a capital p and then once you hit enter it should show up right here then we're going to do is web since this is a web app and then we're going to type in gunacorn so this is what we installed gunnacorn for and then we're going to type in the name of our app file so mines is app.pi so i'm just going to type an app and then app all right since this is an app if your main file name is for instance dot pi you'd put main but since my file name is app i'm just going to put that okay and once we have this done we can move on to creating the app and all now if you already have a github repository for your app you can just skip this process but for the ones that do not have a github repository for their app or basically a github repository to store their code for their app um this is what you're going to do so you're going to go to github.com new and then you're going to put the name of your app as the repository name now since this is just a tutorial i'm just going to put flask for roku deploy you can set it to public or private for the visibility but i'm just going to set it to private and then you're just going to press create repository and once you press create repository on your terminal you're just going to get init and then do git add dot or period and this will basically add all of our files into our repository okay and then we're going to do git commit first commit so we need to basically have some sort of message for our commit and once we have that message we're just going to hit enter and as you can see it has created all these files and then next we're going to set the branch to equal domain so get branch and then hyphen m main and then do git remote add origin and then i'm just going to copy this uh url right here so right there okay and then i'm just gonna do git push hyphen u origin main and once i do this all of our code in our app will be pushed over to this github repository right here so once it says 100 and once this command has been executed you can just go to the repository and as you can see we have all of our app files right all right so i've just cleared my terminal and now since we have pushed our code to the repository we can just create our heroku app and push the code to heroku server so to do this we first need to log in and to login just type in heroku login and it will ask you to press any key to open up the browser so i'll just press return and as you can see it has this login page over here all right so once you're at this login page you can press this login button and for some of you it may ask to fill in your credentials um to log in if you have not logged in yet and if you have logged in prior to this step it'll log you in as soon as you press the button so if i just press this you can see it just logged me in and since i'm logged in we can basically create our app and deploy it from this terminal to create our app we just need to do heroku create and then your app name so i'm just going to do flask hyphen tutorial hyphen deploy and once you run this command it will create the heroku alright so once you have created the app you can just run git push heroku and then the get branch that you want to push so over here if we go to github you can see that the code is in this main branch so i'm just going to type in main and then hit enter and this command will basically deploy our code to heroku and this will take a while so i'm just going to speed up the video alright so once it says your website's name and deployed to roku that means that our app has been deployed and we can just run heroku open to view our app so right here as you can see we have our app so as you guys can see my website has been deployed to heroku and if you guys experience any type of error just run heroku logs and this will show any logs for your app so if there was an error deploying you can run this command and it will have the error listed there now just to show you how this works i can refresh this page on the website and if i run this command again you can see that a get request was sent to slash and it shows at what time and what day also alright guys so that's it for this video i hope you learned something and i hope that this video helped you deploy your flask app if you have any questions or comments please leave them down below and i will do my best to answer them also i apologize for the late upload i've been super busy with school but there will be more videos coming soon so stay tuned for those and as always have a nice one
Info
Channel: Arpan Neupane
Views: 37,432
Rating: undefined out of 5
Keywords: flask, web development, programming, python, coding, python3, coding with python, flask easy, easy programming, python tutorial, python3 tutorial, how to learn flask, how to learn python, coding videos, programming tutorials, python programming, flask development, heroku, how to deploy Flask app to heroku, heroku and python, Python and flask, Flask and heroku, deploy flask app to heroku, how to use heroku, how to deploy to heroku with python, Python Flask and heroku, Flask deploy
Id: D2GLVoiEZyE
Channel Id: undefined
Length: 6min 35sec (395 seconds)
Published: Sun May 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.