调用栈
命令行输入以下命令时 python3 manage.py runserver
command
execute_from_command_line 函数中的 utility.execute() 会根据命令行的参数, 找到对应的 command 对象, 再去调用这个 command 对象的 run_from_argv 方法
服务模型
run 函数中会根据 threading 参数来选择服务模型, threading 默认为 True, 表示使用线程模型, 如果为 False 表示以传入的参数 server_cls 生成服务模型
# django\core\management\commands\runserver.py
def run(addr, port, wsgi_handler, ipv6=False, threading=True, server_cls=WSGIServer):
server_address = (addr, port)
if threading:
httpd_cls = type('WSGIServer', (socketserver.ThreadingMixIn, server_cls), {})
else:
httpd_cls = server_cls
httpd