To deploy any Python application to Heroku platform, we need to create three necessary files - Procfile, requirements.txt, and runtime.txt.
web: python main.py
The above Procfile is the instuction telling Heroku platform to run the main.py module as the entry point for our application to start.
Next, we need to create a requirements.txt file to instuct Heroku platform to install all required packages and modules installed in our virtual environment using pip installer.
myvenv\Scripts\activate pip freeze > requirements.txt
We also need to create a runtime.txt file in which we have to write down the version of Python interpreter needed to run our application.
python-3.8.5
Lastly, we need to write code for our application able to run offline and also on Heroku platform.
#main.py import os from bottle import route, run @route('/') def main(): return "Hello World!" if 'DYNO' in os.environ: run(host='0.0.0.0', port=os.environ.get('PORT', 9000)) else: run(host='localhost', port=9000, debug=True, reloader=True)
To deploy our application to Heroku platform, we have two choices - deploy it directly to the platform or push it first to GitHub and deploy it later to Heroku platform.
GitHub: https://github.com/Sokhavuth/kwblog
Heroku: https://khmerweb-kwblog.herokuapp.com/