drawde83
drawde83

Reputation: 139

Display flask app output in Jupyter notebook

I'm running a basic flask script from a jupyter notebook. I can access it through a web browser but the cell doesn't output the requests log unlike when the script is run from a commandline. Is there a way to display the log in the notebook.

here is the script

%load_ext ipyext.writeandexecute

%%writeandexecute -i myflask myflask.py
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Upvotes: 1

Views: 5223

Answers (1)

drawde83
drawde83

Reputation: 139

Just in case others face the same problem. I've gotten around this by opening a terminal from Jupyter

replace the writeandexecute magic with %%writefile myflask.py

and in a new cell

import subprocess as sub

# this opens a windows terminal
sub.call('start /wait python myflask.py', shell=True)

Upvotes: 4

Related Questions