class WSGIHandler(base.BaseHandler):
request_class = WSGIRequest def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.load_middleware() #载入中间件装饰器 def __call__(self, environ, start_response):#每次请求被调用
set_script_prefix(get_script_name(environ))
signals.request_started.send(sender=self.__class__, environ=environ)
request = self.request_class(environ) #获取WSGIrequest对象,保存header
response = self.get_response(request) #获取response对象,见下方 response._handler_class = self.__class__ status = '%d %s' % (response.status_code, response.reason_phrase) #准备返回状态
response_headers = [
*response.items(),
*(('Set-Cookie', c.output(header='')) for c in response.cookies.values()),
] #准备返回header
start_response(status, response_headers) #返回响应体
if getattr(response, 'file_to_stream', None) is not None and environ.get('wsgi.file_wrapper'):
response = environ['wsgi.file_wrapper'](response.file_to_stream)
return response
handlers/base中:
def get_response(self, request):
"""Return an HttpResponse object for the given HttpRequest."""
# Setup default url resolver for this thread
set_urlconf(settings.ROOT_URLCONF) #设置urls/base.py中的_urlconf.value
response = self._middleware_chain(request) #依次调用中间件后返回response
response._closable_objects.append(request)
if response.status_code >= 400: #异常处理
log_response(
'%s: %s', response.reason_phrase, request.path,
response=response,
request=request,
)
return response

Django WSGI响应过程之WSGIHandler的更多相关文章

  1. python web框架 django wsgi 理论

    django wsgi python有个自带的wsgi模块 可以写自定义web框架 用wsgi在内部创建socket对象就可以了 自己只写处理函数就可以了django只是web框架 他也不负责写soc ...

  2. [TimLinux] django WSGI入口分析及自定义WSGIHandler思路

    1. 命令行启动 命令行是通过runserver子命令来启动的,对应的django模块为django.core.management.commands.runserver,调用关系结构: # 简化的运 ...

  3. tornado和django的结合使用 tornado Server for django WSGI APP

    #!/usr/bin/env python # Run this with # Serves by default at # http://localhost:8080/hello-tornado a ...

  4. Django WSGI,MVC,MTV,中间件部分,Form初识

    一.什么是WSGI? WEB框架的本质是一个socket服务端接收用户请求,加工数据返回给客户端(Django),但是Django没有自带socket需要使用 别人的 socket配合Django才能 ...

  5. Django WSGI Error:class.__dict__ not accessible in restricted mode

    一.问题 今天网站出了一个错误: RuntimeError at /index.html class.__dict__ not accessible in restricted mode 二.原因 用 ...

  6. django rest framwork教程之 viewsets和routers

    ViewSets 和Routers REST框架包括一个用于抽象处理的ViewSets,允许开发人员集中精力对API的状态和交互进行建模,并根据常见约定自动处理URL构造. Viewset 类和 Vi ...

  7. Django请求响应对象

    请求与响应对象 HttpRequest HttpRequest存储了客户请求的相关参数和一些查询方法. path 请求页面的全路径,不包括域名-例如, "/hello/". met ...

  8. django wsgi nginx 配置

    """ WSGI config for HelloWorld project. It exposes the WSGI callable as a module-leve ...

  9. django返回响应对象

    Django的视图必须要返回一个HttpResponse对象(或者其子类对象),不能像flask一样直接返回字符串. Django: return HttpResponse("Hello&q ...

随机推荐

  1. JavaScript中的表单编程

    表单编程 1获取表单相关信息 1.什么是表单元素 1.什么是表单元素 在H TML中表单就是指form标签,它的作用是将用户输入或选择的数据提交给指定的服务器 2.如何获取表单元素 <form ...

  2. 修改sql server表字段的字符串

    网站标题被注入黑链接,使用sql脚本update修改字段内的字符串截取UPDATE [qds0460132_db].[dbo].[Blood_News]   SET [Blood_Name] = SU ...

  3. Day 6:集合(set)

    集合(set)定义:由不同元素组成的集合,集合中是一组无序排列的可hash值,可以作为字典的key特性:集合里面数据类型是不可变的1.可变的数据类型:列表,字典2.不可变的数据类型:数字.元组.字符串 ...

  4. 面试系列八 es写入数据的工作原理

    (1)es写数据过程 1)客户端选择一个node发送请求过去,这个node就是coordinating node(协调节点) 2)coordinating node,对document进行路由,将请求 ...

  5. 历经小半宿吧。哎,终于搭建好了Linux-C的环境

    小小地庆祝一下吧   继续努力学习,把Linux-C熟悉一下,争取做到会用吧...   我想应该不难   我熟悉的 iostream 还存在   可惜,微软基础类库不在了...

  6. Single Thread Execution 能通过这座桥的只有一个人

    直奔主题, Single Thread Execution也称作Critical Section(临界区),范例如下: public class SingleThreadGate { public s ...

  7. 如何为ABAP程序添加权限检查

    一.确认权限对象,及其关联字段: TCode: SU21 例如权限对象"M_MSEG_WMB",它关联字段为"WERKS",详见下图: 二.在ABAP代码中添加 ...

  8. ON_WM_TIMER() void (__cdecl xx::* )(UINT)”转换为“void (__cdecl CWnd::* )(UINT_PTR)

     ON_WM_TIMER()在编译器从32位转换为64位的时候, 出现的问题; class CFlatComboBox : public CComboBox   (基类为CWnd) 为了重载CWnd的 ...

  9. 小程序swiper-item内容过多显示不全的解决方案

    最近在项目遇到swiper高度不能自适应,导致swiper-item 里面的内容过多时只能显示一部分,最终解决方案:<swiper current="{{currentTab}}&qu ...

  10. js获取json的健与值

    let myObj = { name: '张三', age: 18,sex:'女' } let tempArr = Object.keys(myObj) console.log(tempArr) fo ...