码迷,mamicode.com
首页 > 其他好文 > 详细

flask run方法和run_simple

时间:2018-09-05 23:52:55      阅读:2786      评论:0      收藏:0      [点我收藏+]

标签:rom   ber   ret   keyword   name   reload   pre   info   local   

1.Flask提供的Web服务器不适合在生产环境中使用

2.run方法启动flask集成的服务器:

例:

if __name__ == ‘__main__‘:
    app.run(debug=True)

 

 

3.源码:

def run(self, host=‘localhost‘, port=5000, **options):
        """Runs the application on a local development server.  If the
        :attr:`debug` flag is set the server will automatically reload
        for code changes and show a debugger in case an exception happened.

        :param host: the hostname to listen on.  set this to ``‘0.0.0.0‘``
                     to have the server available externally as well.
        :param port: the port of the webserver
        :param options: the options to be forwarded to the underlying
                        Werkzeug server.  See :func:`werkzeug.run_simple`
                        for more information.
        """
        from werkzeug import run_simple
        if ‘debug‘ in options:
            self.debug = options.pop(‘debug‘)
        options.setdefault(‘use_reloader‘, self.debug)
        options.setdefault(‘use_debugger‘, self.debug)
        return run_simple(host, port, self, **options)

 

 

从源码中可以看出,Flask集成的run方法是由werkzeug中的run_simple方法提供的。run()接受debug参数时,options.pop(‘debug‘),设定’use_reloader’默认参数为self.debug,’use_debugger’为self.debug.

4.总结

依赖werkzeug

flask run方法和run_simple

标签:rom   ber   ret   keyword   name   reload   pre   info   local   

原文地址:https://www.cnblogs.com/qunxiadexiaoxiangjiao/p/9594879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!