Flask is a micro web framework written in Python meant for easy and quick development of web apps. It can be used to create small web apps and is easy to use. It is meant for server side scripting and uses the Jinja2 templating engine for rendering web pages.
Deploying Flask web apps on Heroku can be quite a tricky task, especially when the official docs are outdated. On Heroku, when it comes to deploying web apps written with Flask, it requires you to download the Heroku CLI and then proceed further. Well, there's another way to do it as well and that is by installing dependencies on the go and deploying the Flask app by connecting the GitHub repository to your Heroku app.
Here, is a sure short way of successfully deploying a web app on Heroku.
1) Create a new repository and add a .gitignore file for Python under the drop down menu while creating it
To add the .gitignore file to a pre-existing repository, go to the repository settings and add it.
3) In the IDE clone the repository. I've used PyCharm where I have cloned my GitHub repository using 'Get from Version Control' option in PyCharm. It helps you to create a new folder and save your code here so it will be easy to commit and push any changes in the code to your GitHub
4) Now move all the existing code to the new folder you just created or simply create a new file and write your code. This folder also contains the .gitignore file
6) Install all the needed dependencies, including gunicorn which is a WSGI HTTP server, using
pip install gunicorn and test your app locally, in the virtual environment you created
8) Now create a new file, name it Procfile and type
web: gunicorn --bind 0.0.0.0:$PORT app:app. Here app will be your app (main file) name
A Procfile is a text file (named Procfile) placed in the root of your app that lists the process types in the app. Heroku apps include a Procfile that specifies the commands that are executed by the app on startup.
10) Now got to Heroku, login and create a new app
13) Click on 'View' to view your deployed app
You can now be able to access the active deployment under the Environments section of your GitHub repository
And that’s the easiest way of deploying a Flask app on Heroku by connecting it to your GitHub repository! :)