首页 > 其他 > 详细

flask 源码专题(一):请求上下文与全文上下文

时间:2020-04-04 12:48:56      阅读:62      评论:0      收藏:0      [点我收藏+]

源码解析

0. 请求入口   

if __name__ == __main__:
    app.run()
def run(self, host=None, port=None, debug=None,
        load_dotenv=True, **options):
    # Change this into a no-op if the server is invoked from the
    # command line. Have a look at cli.py for more information.
    if os.environ.get(FLASK_RUN_FROM_CLI) == true:
        from .debughelpers import explain_ignored_app_run
        explain_ignored_app_run()
        return
 
    if get_load_dotenv(load_dotenv):
        cli.load_dotenv()
 
        # if set, let env vars override previous values
        if FLASK_ENV in os.environ:
            self.env = get_env()
            self.debug = get_debug_flag()
        elif FLASK_DEBUG in os.environ:
            self.debug = get_debug_flag()
 
    # debug passed to method overrides all other sources
    if debug is not None:
        self.debug = bool(debug)
 
    _host = 127.0.0.1
    _port = 5000
    server_name = self.config.get(SERVER_NAME)
    sn_host, sn_port = None, None
 
    if server_name:
        sn_host, _, sn_port = server_name.partition(:)
 
    host = host or sn_host or _host
    port = int(port or sn_port or _port)
 
    options.setdefault(use_reloader, self.debug)
    options.setdefault(use_debugger, self.debug)
    options.setdefault(threaded, True)
 
    cli.show_server_banner(self.env, self.debug, self.name, False)
 
    from werkzeug.serving import run_simple
 
    try:
        run_simple(host, port, self, **options)
    finally:
        # reset the first request information if the development server
        # reset normally.  This makes it possible to restart the server
        # without reloader and that stuff from an interactive shell.
        self._got_first_request = False

 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

flask 源码专题(一):请求上下文与全文上下文

原文:https://www.cnblogs.com/qiu-hua/p/12631008.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!