Warning message while running Flask

后端 未结 9 1498
有刺的猬
有刺的猬 2020-12-07 13:07

While I am running Flask code from my command line, a warning is appearing:

Serving Flask app \"hello_flask\" (lazy loading)
* Environment: production
  WARN         


        
相关标签:
9条回答
  • 2020-12-07 13:42

    in configurations or config you can add this code : ENV = ""

    same as if you try to add debug set to true like this DEBUG = True

    for more detail you can check this http://flask.pocoo.org/docs/1.0/config/#ENV

    0 讨论(0)
  • 2020-12-07 13:42

    If you encounter NoAppException and you see lazy loading the following seemed to fix the issue:

    cd <project directory>
    export FLASK_APP=.
    export FLASK_ENV=development
    export FLASK_DEBUG=1
    
    0 讨论(0)
  • 2020-12-07 13:49

    To remove the "Do not use the development server in a production environment." warning, run:

    export FLASK_ENV=development

    before flask run.

    0 讨论(0)
  • 2020-12-07 13:55

    I have been using flask for quite some time now, and today, suddenly this warning turned up. I found this.

    As mentioned here, as of flask version 1.0 the environment in which a flask app runs is by default set to production. If you run your app in an older flask version, you won't be seeing this warning.

    New in version 1.0.

    Changelog

    The environment in which the Flask app runs is set by the FLASK_ENV environment variable. If not set it defaults to production. The other recognized environment is development. Flask and extensions may choose to enable behaviors based on the environment.

    0 讨论(0)
  • 2020-12-07 13:56

    Try gevent:

    from flask import Flask
    from gevent.pywsgi import WSGIServer
    
    app = Flask(__name__)
    
    @app.route('/api', methods=['GET'])
    def index():
        return "Hello, World!"
    
    if __name__ == '__main__':
        # Debug/Development
        # app.run(debug=True, host="0.0.0.0", port="5000")
        # Production
        http_server = WSGIServer(('', 5000), app)
        http_server.serve_forever()
    

    Note: Install gevent using pip install gevent

    0 讨论(0)
  • 2020-12-07 14:00

    First, try to the following :

    set FLASK_ENV=development 
    

    then run your app.

    0 讨论(0)
提交回复
热议问题