Dead simple heroku flask app
Abhishek Kori
Product Manager | Wholesale Lending, Commercial Real estate | Skills: Product, Project Management, UI/UX, Programming, Data Analysis, Data Governance, Visualization, Communication | PSPO?
Hi guys, it has been long time i built any app and host it on heroku. Today i was just trying to build a simple flask app and host it there. The tutorials which found on web were pretty complex and did more than what i needed. So with combination of few other articles, github repo, official guide and stackoverflow i could host it.
Here is a very simple guide which will help you get started with flask app on heroku :D
Step 1: Install flask
pip install flask
Step 2: Build a simple flask app in your local and run it
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():return 'Hola! Linkedin <3'
if __name__ == "__main__":
app.run()
Step 3: Run it!
python app.py
Open your favourite browser and check at https://locahost:5000/. You should see your app running.
Now that our app is running in our local environment lets deploy this to heroku.
Step 4: Signup for a free heroku account if you don't have one.
Step 5: Create your new app in heroku dashboard. The app name should be unique. Select the region
Step 6: Install heroku cli. Its pretty straight forward :P
Step 7: Login into your heroku account via heroku cli
heroku login
Enter your heroku account email and password
Step 8: Initialise your project
cd <My-Project>/
git init
Step 9: we need to tell the heroku git the name of the app which you created in Step 5. To do that
heroku git:remove -a <Your-App-Name-Here>
Step 9: Create a file called requirements.txt. Add the below contents
Jinja2==2.6 gunicorn==0.17.2 Flask==0.10.1 Werkzeug==0.10.4
Here we are adding gunicorn because Heroku does not provide web server.
Step 10: Create a file with name Procfile . Procfile is where you tell heroku what command to run once app is deployed
Note: Procfile does not have file extension, just file with name Procfile
Add the below content in your Procfile
web: gunicorn app:app
Now you are set to deploy the app to heroku
Step 11: git add all, git commit and do git push
git add *
git commit -m "inital commit"
git push heroku master
You can see the logs which will push your source code, download the dependencies and run the app.
Step 12: Open your app at <your-heroku-app-name>.heroku.com
Vola! your app should be running
Let me know in comments if this was helpful and if you require any help <3
Team Architect, Development Expert @ SAP Signavio
6 年Good one! And, great going :)
Co-Founder & CTO @Edstruments (we're hiring!)
6 年You should write an extension on this and show people how to run Flask apps using Apache2 or Nginx! Great tutorial as always! I usually stick to Django due to its features more than anything else