Live Demo - https://flaskdemobasic.herokuapp.com
-
Create a virtual environment
- In Windows
virtualenv env cd env\Scripts .\activate
- In Linux/Mac
virtualenv env source env/bin/activate
-
Install Flask Module
pip install Flask --upgrade
-
Create a .gitignore file and add the following lines
__pycache__/ *.py[cod] .vscode env/
-
Sample Flask app which returns current Date
from flask import Flask from datetime import datetime app = Flask(__name__) @app.route('/') def func(): return str(datetime.now()) if __name__ == '__main__': app.run()
-
Run the app
python app.py
When you goto http://localhost:5000/ you should be able to see current date and time.
-
Create a new file and name it as Procfile in the project's root folder and add the following text
web: gunicorn app:app
-
Add guicorn module and other installed modules to requirements.txt
pip install gunicorn --upgrade pip freeze > requirements.txt
-
Specify a python runtime. Example: python-3.6.2
- Create a file called runtime.txt in the project's root folder and add the following text
python-3.6.2
-
Create a heroku app
heroku create flaskdemoapp
-
Initialize git and add remote as heroku
git init git remote add prod [email protected]:flaskdemoapp.git
-
Commit and push
git add . git commit -m "Your message" git push -u prod master
-
Incase if you had not added public key, then
heroku login #Username & Password heroku keys:add ~/.ssh/id_rsa.pub