Flask is a web application framework written in Python. Flask is based on the Werkzeug WSGI toolkit and Jinja2 template engine. Both are Pocco projects. This article revolves around how to deploy a flask app on Heroku. To demonstrate this, we are first going to create a sample application for a better understanding of the process.
- Heroku CLI
Deploying Flask App on Heroku
Let’s create a simple flask application first and then it can be deployed to heroku. Create a folder named “eflask” and open the command line and cd inside the “eflask” directory. Follow the following steps to create the sample application for this tutorial.
STEP 1 : Create a virtual environment with pipenv and install Flask and Gunicorn .
$ pipenv install flask gunicorn
STEP 2 : Create a “Procfile” and write the following code.
$ touch Procfile
$ touch runtime.txt
STEP 4 : Create a folder named “app” and enter the folder.
$ mkdir app $ cd app
STEP 5 : Create a python file, “main.py” and enter the sample code.
STEP 6 :Get back to the previous directory “eflask”.Create a file“wsgi.py” and insert the following code.
$ cd ../ $ touch wsgi.py
STEP 7 : Run the vitual environment.
$ pipenv shell
STEP 8 : Initialize an empty repo, add the files in the repo and commit all the changes.
$ git init $ git add . $ git commit -m "Initial Commit"
STEP 9 : Login to heroku CLI using
Now, Create a unique name for your Web app.
$ heroku create eflask-app
STEP 10 : Push your code from local to the heroku remote.
$ git push heroku master
Finally, web app will be deployed on http://eflask-app.herokuapp.com.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to deploy React app to Heroku?
- How to Deploy Django application on Heroku ?
- How to Deploy a Basic Static HTML Website to Heroku?
- Deploy Machine Learning Model using Flask
- How to upload Laravel App to Heroku Cloud Application Platform
- Create a Weather app using Flask | Python
- Todo list app using Flask | Python
- Dockerize your Flask App
- Flask project - Create a Joke App with PyJokes
- Introduction and Installation of Heroku CLI on Windows machine
- Deploy cloud function on Google Cloud Platform
- How to Deploy Your React Websites on GitHub?
- Guide to deploy containers on Google Cloud Run
- Deploy a Machine Learning Model using Streamlit Library
- How to Deploy Django project on PythonAnywhere?
- Introduction to Xamarin | A Software for Mobile App Development and App Creation
- Deploying Your Web App using Azure App Service
- Progressive Web App - A Combination of Native and Web App
- Python | Using for loop in Flask
- Python | Introduction to Web development using Flask
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.