- Import necessary modules:
from flask import Flask
- Create Flask instances for each application:
app1 = Flask(__name__)
app2 = Flask(__name__)
- Define routes for each application:
@app1.route('/app1')
def app1_route():
return 'Hello from App 1'
@app2.route('/app2')
def app2_route():
return 'Hello from App 2'
- Run each application with different port numbers:
if __name__ == '__main__':
app1.run(port=5000)
app2.run(port=5001)
- Save the script with a filename (e.g.,
multiple_apps.py
) and run it in the terminal:
python multiple_apps.py
- Access each application in a web browser using the specified port numbers:
- App 1: http://localhost:5000/app1
- App 2: http://localhost:5001/app2