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. flutter中的BuildContext

    https://www.jianshu.com/p/509b77b26b78

  2. jquery学习笔记(三):事件和应用

    内容来自[汇智网]jquery学习课程 3.1 页面加载事件 在jQuery中页面加载事件是ready().ready()事件类似于就JavaScript中的onLoad()事件,但前者只要页面的DO ...

  3. JS break语句和continue语句

    break语句 描述:break语句,用于无条件结束各种循环(退出循环)和switch. 说明:一般情况下,需要在break语句之前加一个条件判断.换句话说:就是条件成立了,就退出循环 continu ...

  4. 微信小程序(mpvue框架) 购物车

    效果图: 说明:全选/全不选, 1.数据: products:[{checked:true,code:"4",echecked:false,hasPromotions:true,i ...

  5. 17-7-es6作用域

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. js 删除数组中指定值

    var arr = ['1','2'];delete('1'); function delete(i){ var index = arr.indexOf(i); arr.splice(index, 1 ...

  7. springboot2.0 使用aop实现PageHelper分页

    参考: https://blog.csdn.net/qq_24076135/article/details/85212081 https://www.jianshu.com/p/036d31ae77d ...

  8. loj2513 治疗之雨

    题意:你的英雄一开始血量为p,你还有m个队友,血量无穷.血量上限为n,下限为0.如果血量满了就不能加血.每次启动操作,随机给m+1个英雄加1点血,然后等概率随机k次每次对于英雄扣1点血.求期望操作几次 ...

  9. 关于公式文件.eqn

    建议默认打开该选项

  10. 2016.11.5初中部上午NOIP普及组比赛总结

    2016.10.29初中部上午NOIP普及组 这次比赛算是考的最差的一次之一了,当中有四分之三是DP. 进度: 比赛:没分+0+没分+40=40 改题:AC+0+没分+40=140 TurnOffLi ...