Django的runserver

当年执行 python manage runserver命令时

1. 先执行 runserver 中的 handle方法

2. 执行 self.run()方法

3. 执行 self.inner_run()

3.1 inner_run 下 run方法的封装

3.1.1 接着看 handle 怎么来的 封装了一个方法 接着找返回函数
3.1.2在 basehttp 下
3.1.3 get_wsgi_application() 是wsgi.py下的方法
3.1.4 WSGIHandler (django.core.handlers.wsgi.WSGIHandler) 继承 base.BaseHandler

3.2 import_string() 是 django.utils.module_loading 的 import_string方法

3.3 接着看 self.server_cls 是 django.core.servers.basehttp import WSGIServer导入的

Django 在这部分代码中通过自定义的 WSGIServer 类与 WSGI 服务器进行关联。

具体来说,Django 使用 WSGIServer 作为服务器基础类,它继承了 wsgiref.simple_server.WSGIServer,并且根据需要扩展了相关功能,例如支持 IPv6 和定制错误处理等。

4. run()封装好了 接着开始执行

4.1 httpd.set_app(wsgi_handler)

set_app 执行的是 from wsgiref.simple_server import WSGIServer 下的方法

4.2 httpd.serve_forever()

serve_forever 执行的是 from socketserver import BaseServer

相关推荐
考虑考虑3 小时前
cmd局部设置java变量
运维·后端·自动化运维
2601_962078194 小时前
Python中calendar.weekday用法
python·编程技巧·calendar·日期处理·weekday
2601_962218614 小时前
万象生鲜系统业财一体化底层打通技术自动生成经营账单
大数据·数据库·人工智能·python·算法
2601_966949654 小时前
为什么量化策略需要大量历史股票数据?从回测可信度理解数据规模
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
2601_962885724 小时前
如何用 Python 扫描 A 股跳空缺口并统计缺口回补概率?
java·前端·python
李高钢4 小时前
Python FastAPI 框架入门:从零搭建你的第一个高性能 API 服务
数据库·python·fastapi
ocean21035 小时前
2025-2026年Python面试高频知识点洞察
开发语言·python·面试·python八股文
Warson_L5 小时前
Python的OrderedDict
python
隐擎fox5 小时前
高性能网络爬虫架构设计:基于 Python 的长连接复用与分布式会话池调度实践
分布式·python·网络协议·tcp/ip·高并发·网络爬虫、
Warson_L5 小时前
Python的TypedDict
python·langchain·llm