Skip to the content.

Python Flask in Jupyter • 1 min read

```python %%python –bg

from flask import Flask, jsonify from flask_cors import CORS

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 InfoDb = []

# add a row to list, an Info record
InfoDb.append({
    "FirstName": "Drishya",
    "LastName": "Mody",
    "DOB": "July 15, 2006",
    "Residence": "San Diego",
    "Email": "drishyam60014@stu.powayusd.com",
})

add an HTML endpoint to flask app

@app.route(‘/’) def say_hello(): html_content = “”” <html> <head> Hellox </head> <body> <h2>Hello, World!</h2> </body> </html> “”” return html_content

if name == ‘main’: # starts flask server on default port, http://127.0.0.1:5001 app.run(port=5001)