Flask - Deploy on Heroku with Gunicorn
Heroku works with Git. You create your projects on a local computer, and manage the version control with Git. Then, push the project to heroku master and deploy by few setting.
Prepare a flask project.
from flask import Flask
app = Flask(__name__)@app.route(‘/’)
return ‘Hello, World!’if __name__ == ‘__main__’:
requirements.txt. Remember to add gunicorn package.
Procfile without a file extension.
web gunicorn app:app
app:app is the filename of app.py where flask application initiated.
Use Git to manage version control.
For example, in terminal,
git add .
git commit -m <message>
If your python project run on virtual environment, adding
.gitignore to exclude the directory v
env/. There is no need to use virtual environment in heroku. It was not working when I included it.
In terminal, login heroku account.
The terminal will open browser for login page.
After login, back to terminal.
cd project_location/heroku create <project-name>
heroku git:remote -a <project-name>git push heroku master # Push the project to heroku and Deploy
At this moment, the flask web server should be deployed successfully on heroku. You can open the web by using the command in terminal.
If there is something wrong, using the command in terminal to see logs.
heroku logs — tail
As a beginner, I am trying to use the easiest way to build up a website. Thanks for reading .