Skip to main content

Deploy Flask app on Heroku with example guide

Deploying a python flask app has many ways to do, and there is a lot of platforms available
Here I am going to show how to deploy a python flask application on Heroku in a free plan

Let's Get started

I assume You already developed your flask application in your local environment, have a Heroku account, and have some basic knowledge of working with git and Command-line Interface.

Else If you are new Python Flask, Checkout the amazing course from Pluralsight called
Introduction to the Flask Microframework by Reindert-Jan Ekker

Signup-now with 50% offer



why Heroku?

Heroku Free account provides 550 free dyno hours and free domain
Example: https://app_name.herokuapp.com.
 Learn more at Heroku Free Dyno Hours

Heroku Provide some option to Deploy App: 

First one is deployed your app by linking your GitHub repository with your Heroku Account
Another one is using the Heroku Command-line Interface (Heroku CLI) by pushing the application on Heroku git servers

Here in this post, I will demonstrate how to deploy the flask app by linking your GitHub repository with Heroku

1: Deploy your app on GitHub:

Develop your application and initialize and commit your changes with git on your local work base 
if you new to git checkout the amazing course from the Pluralsight
Code School: Git Real by Olivier Lacan and Gregg Pollack Signup-now with 50% offer 

Here in the example, I am making local repository contain one simple flask app called app.py



2: Install a web server called Gunicorn

In order to host application Heroku, we need to install a webserver called Gunicorn.

Run the following command in your command line to install gunicorn   

                                           pip install gunicorn


deploy flask app on heroku


3: Create a requirements.txt file

Now you want to output all your dependent packages for that application needs in a file called requirements.txt
run the following command in your command line

                                        pip freeze > requirements.txt

check the requirements.txt contains all your required packages to run the application
                                         cat requirements.txt




4: Create a Procfile:

Procfile is a mechanism for declaring what commands are run by your application’s dynos on the Heroku platform.

Create the file in name of Procfile    there is no Extension  and their P is Upper case

paste that following lines on Procfile

                                                         web gunicorn app:app



Here web is used by Heroku to start a web server for the application
app:app denotes that module and application name in our case both are called app if it differs on your application change that accordingly

5: Push that repository on Github:

Create a repository on GitHub
add and commit your files in the local repository 



And push that on the GitHub  master branch

Example Screenshots:




6: Create an App on Heroku:

Before creating an app make sure your GitHub account is connected with Heroku Account 

then create an app on Heroku here is the example 
deploy flask app on heroku



Open your Heroku app go to deploy option 

select the Deployment method as  Github, 

Search your repository with a name and click connect 

Deploy:

On the below, you can see the manual deploy option 
select your branch name in the case it is a master branch

deploy flask app on heroku

Click the deploy branch option 

Now your app started to deploy on Heroku wait for some time 

deploy flask app on heroku



after the successful message popup view your app by that URL 
https://yourapplicationname.herokuapp.com

in the case, https://deploy-flask-app.herokuapp.com/ is my URL 
deploy flask app on heroku


Finish Now you have successfully deployed your application on Heroku 

If you see "Application Error"?


If you see the Any application error once again check your Procfile and make sure your python run time is supported by Heroku >  Heroku Python Support

Thank you for reading...


checkout the best online skill learning platform Pluralsight with 7000+ courses from industry level trained teachers Sign-up now with 50% offer



Comments

Popular posts from this blog

#1 Build your first chatbot using Python and AIML

In the series of post, I am going to build own chatbot using python and AIML  How to build a Chatbot: In this series, we gonna develop our chatbot as a simplest as possible using python and the AIML is brain Chatbot using python and AIML what is AIML: AIML stands for Artificial Intelligence Markup language It looks like XML files, developed by Dr. Richard S. Wallace during 1995-2000,  It is a set of tags and patterned structure, constructed by question and answers It makes our chatbot brain as simple as possible python: Everybody knows what is python language, it's one of the popular programmings in time it has multiple packages available in their packages repository both internally and externally As on the list, AIML package also available is python. You can easily install the packages using python pip(python package manager), or any other ways. The package helps to read and learn the AIML files into python and return the appropriate response 

[Solved] Linux mint, Ubuntu audio problem

The Linux operating systems gets a gradual increase of  user base level and also it improves user-friendly interface and other essential components like windows  But anyway still some Linux users Face some problems in our systems, Most common was audio problem, sometimes the sound will be muted automatically,  The audio problem-related questions are most frequently question in Linux and ubuntu forums, somebody gets a solution or but still few struggled with this problem. I am also facing this problem in past weeks, afterwards, I can find the one solution In this post, I am sharing how to fix audio problem in Linux mint or Ubuntu systems Restart Alsamixer : Alsa mixer (Advanced Linux Sound Architecture ) is a Graphical mixer program used in Linux Mint and Ubuntu systems, sometimes it may be worked incorrect, so at this time the audio problems will be occur So try to Restart the program by using this command in terminal: