在Jupyter笔记本中显示Flask应用程序输出 [英] Display flask app output in Jupyter notebook
本文介绍了在Jupyter笔记本中显示Flask应用程序输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从jupyter笔记本上运行基本的flask脚本.我可以通过Web浏览器访问它,但是与从命令行运行脚本不同,该单元不会输出请求日志.有没有一种方法可以在笔记本中显示日志.
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.
这是脚本
%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()
推荐答案
以防其他人遇到相同的问题.我通过从Jupyter打开终端来解决这个问题
Just in case others face the same problem. I've gotten around this by opening a terminal from Jupyter
用%% writefile myflask.py替换writeandexecute魔术
replace the writeandexecute magic with %%writefile myflask.py
并在一个新单元格中
import subprocess as sub
# this opens a windows terminal
sub.call('start /wait python myflask.py', shell=True)
这篇关于在Jupyter笔记本中显示Flask应用程序输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文