Use this link to apply and setup the BTP trial or enterpise enviroment
Python
Option1:
Install and setup from python offical website
Option2:
Install and setup from python-guide
IDE
we can use the VSC as you favourite development IDE, or other IDE you like.
- VSC Install the python extension
Steps:
-
download the dependency , vitualenv and flask
pip install virtualenv pip install Flask
-
create the project folder and Initializa vitual enviroment
mkdir demo cd demo virtualenv flask
-
add file app.py with the below simple python code
python code :
from flask import Flask import os app = Flask(__name__) cf_port = os.getenv("PORT") @app.route('/') def hello_world(): return 'Hello this is the BTP python demo!' if __name__ == '__main__': if cf_port is None: app.run(host='0.0.0.0', port=5000, debug=True) else: app.run(host='0.0.0.0', port=int(cf_port), debug=True)
-
Run python project via command line
python app.py
-
Test with the link mentioned inthe command line
- after you get the below response , your python applicaiton is runtime fine
Hello this is the BTP python demo!
Deploy for BTP:
-
set cloud foundry endpoint via command :
cf api {EndpointURL}
-
login to your BTP endpoint with your btp user and password
command :
cf login
-
add manifest.yml for CF BTP development
-
configure the route and python buildpacks
-
Before config the python buildpack , we need to add 3 files(runtime.text, requirement.txt procfile ) according to guide
runtimetime.text: used to defined the python runtime version, we can find the right python runtime releaes via the pythonBuildPackage Relaese
example code :
3.8.10
requirement.txt :used to give the python applicaiton denpendency
example code :
Flask==2.0.1
procfile: define the python applicaiton start comand
example code :
web: python app.py
-
confgure the routes here we suggest use bellow format as recomendation :
{subdomain}-{appname}.{cfappdoman}
subdomain:
appname: defined by business
cfappsdomain: user the command
cf domains
to get the domain urlExample:
--- applications: - name: pyApp memory: 128MB buildpacks: - python_buildpack routes: - route: 91ccc175trial-pythonapp.cfapps.ap21.hana.ondemand.com
-
-
Deploy your nodjs project to your BTP Subaccount
command :
cf push
- Navigte to your space
- Go you applcation
- Get applicaiton URL
-
Test it with the URL
{applicaitonURL}/#/
after you get the below response , your python applicaiton is runtime fine
Hello this is the BTP python demo!
Create and deploy python app: btp-pyton-deploy
Flask guide : flask Guide