%%python
# Using the --bg allows us to run the cell in the background, so we can continue to use the notebook while the server is running. For Debugging purposes, we will keep --bg commented out.
from flask import Flask, jsonify
from flask_cors import CORS
#If You are experienceing issues please reffer to the upper code and run those two commands.
# initialize a flask application (app)
app = Flask(__name__)
CORS(app, supports_credentials=True, origins='*') # Allow all origins (*)
# ... your existing Flask
# add an api endpoint to flask app
@app.route('/api/data')
def get_data():
# start a list, to be used like a information database
CarModels = []
# Add information about a car model
CarModels.append({
"Brand": "Toyota",
"Model": "Camry",
"Color": "Silver",
"Price": "$25000",
"Year": "2022"
})
# Add information about another car model
CarModels.append({
"Brand": "Honda",
"Model": "Civic",
"Color": "Blue",
"Price": "$23000",
"Year": "2021"
})
return jsonify(CarModels)
# add an HTML endpoint to flask app
@app.route('/')
def say_hello():
html_content = """
<html>
<head>
<title>Car Models</title>
</head>
<body>
<h2>Car Models</h2>
<ul>
</ul>
</body>
</html>
"""
return html_content
if __name__ == '__main__':
print("Starting Python Flask Server For Home Page")
# starts flask server on default port, http://127.0.0.1:5001
app.run(port=5001)
# Once the flask app is up and running you should see this below: Starting Python Flask Server For Home Page
# * Serving Flask app '<stdin>'
# * Debug mode: off
#WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
# * Running on http://127.0.0.1:5001
#Press CTRL+C to quit
#Process is interrupted.