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
原文:https://www.cnblogs.com/qiu-hua/p/12631008.html