debug Flask server inside Jupyter Notebook

后端 未结 2 768
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 11:45

I want to debug small flask server inside jupyter notebook for demo.

I created virtualenv on latest Ubuntu and Python2 (on Mac with Python3 this error occurs as well), p

2条回答
  •  生来不讨喜
    2021-02-04 12:39

    I installed Jupyter and Flask and your original code works.


    The flask.Flask object is a WSGI application, not a server. Flask uses Werkzeug's development server as a WSGI server when you call python -m flask run in your shell. It creates a new WSGI server and then passes your app as paremeter to werkzeug.serving.run_simple. Maybe you can try doing that manually:

    from werkzeug.wrappers import Request, Response
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route("/")
    def hello():
        return "Hello World!"
    
    if __name__ == '__main__':
        from werkzeug.serving import run_simple
        run_simple('localhost', 9000, app)
    

    Flask.run() calls run_simple() internally, so there should be no difference here.

提交回复
热议问题