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

相关推荐
hhy_smile22 分钟前
Python environment and installation
开发语言·python
沐雨风栉44 分钟前
用 Kavita+cpolar 把数字书房装进口袋
服务器·开发语言·数据库·后端·golang
莫非王土也非王臣1 小时前
网页端的TensorFlow开发实践
人工智能·python·tensorflow
喵手1 小时前
Python爬虫零基础入门【第七章:动态页面入门(Playwright)·第3节】优先 API:用 Network 找接口,回到 Requests(更稳定)!
爬虫·python·playwright·python爬虫实战·python爬虫工程化实战·python爬虫零基础入门·优先 api
我送炭你添花1 小时前
Pelco KBD300A 模拟器:12.设备仿真与虚拟响应生成
python·自动化·运维开发
郑州光合科技余经理2 小时前
同城020系统架构实战:中台化设计与部署
java·大数据·开发语言·后端·系统架构·uni-app·php
一晌小贪欢2 小时前
深入解析 Python 3.11 版本迭代:性能飞跃与更优雅的错误处理
python·python基础·python3·python3.11·python小白
理智.6292 小时前
根据requirements.txt 完成环境中的依赖库导入
python·conda·pip
Blossom.1182 小时前
用纯 NLP 打造「零样本」时序预测模型:文本化序列 + LLM 的实战路线
人工智能·python·深度学习·机器学习·自然语言处理·架构·transformer
小二·2 小时前
Python Web 开发进阶实战:AI 编排引擎 —— 在 Flask + Vue 中构建低代码机器学习工作流平台
前端·人工智能·python