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

相关推荐
Smilecoc4 小时前
ChromeDriverManager:自动下载和管理chromedriver版本
开发语言·python
0思必得04 小时前
[Web自动化] Selenium元素定位
前端·python·selenium·自动化·html
weixin_419658314 小时前
UISpy:Windows 界面控件的“显微镜“[特殊字符]
windows·python·测试工具·ui
不如语冰5 小时前
AI大模型入门1.1-python基础-数据结构
数据结构·人工智能·pytorch·python·cnn
知行合一。。。5 小时前
Python--04--数据容器(列表 List)
开发语言·python
杰瑞哥哥5 小时前
【时间序列与深度学习】(一)经济计量基础ARIMA模型
python·时间序列·金融工程
网安CILLE5 小时前
Wireshark 抓包实战演示
linux·网络·python·测试工具·web安全·网络安全·wireshark
王夏奇5 小时前
python中的基础知识点-1
开发语言·windows·python
叫我辉哥e15 小时前
新手进阶Python:办公看板集成多数据源+ECharts高级可视化
开发语言·python·echarts
程序员敲代码吗5 小时前
如何从Python初学者进阶为专家?
jvm·数据库·python