$pip install flask gunicorn
// ./app.py
app = Flask(__name__)
@app.route('/')
def index():
return 'Yo, it's working!'
if __name__ == "__main__":
app.run()
put those dependencies in a file named requirements.txt
$pip freeze > requirements.txt
create a Procfile and append the following text format: <process_type>:
- activate
web
application - gunicor is a tool for developing WSGI in Python
web: gunicorn app:app
$python app.py
suppose we create an app called flask-deploy-blog
- login
$heroku login
- create a new Git repository
$cd my-project/
$git init
$heroku git:remote -a flask-deploy-blog
- create a new Heroku App
#if <app-name> is empty, Heroku will generate a random one.
$heroku create <app-name>
- assign the Heroku App to the project
# -a option is followed by <app-name>
$heroku git:remote -a <app-name>
- deploy the application
$git add .
$git commit -am "make it better"
$git push heroku master
For the 1st time, configuration is needed for Heroku(we need a machine to run server)
heroku ps:scale web=1
by web browser
https://<Heroku app name>.herokuapp.com
or by terminal
$heroku open
.gitignore: for those we don't expect to push those irrevelent file on web
# my-project/.gitigore
my-project
*.pyc
__pycache__
staticfiles
db.sqlite3