Display flask app output in Jupyter notebook

醉酒当歌 提交于 2019-12-14 04:22:27

问题


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()

回答1:


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)


来源:https://stackoverflow.com/questions/41657127/display-flask-app-output-in-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!