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. docker删除未使用到的镜像

    docker image prune -a docker image prune -a -f  #-f强制,不需要确认

  2. js 忘记密码发送短信记录cookie

    <div class="forgetPwdBox" style="display:none"> <div class="forTit ...

  3. OBJC依赖库管理利器cocoapods 安装及使用详细图解

    cocoapods: github:https://github.com/CocoaPods/CocoaPods 官方网站:http://www.cocoapods.org/ 1.安装 RubyGem ...

  4. EL fmt标签

    c:formate 表达式需要传入的对象为date

  5. VS2010-MFC(对话框:消息对话框)

    转自:http://www.jizhuomi.com/software/171.html 前面几节讲了属性页对话框,我们可以根据所讲内容方便的建立自己的属性页对话框.本节讲解Windows系统中最常用 ...

  6. day 50 MySQL数据备份与还原(mysqldump)

      MySQL数据备份与还原(mysqldump)   一 mysqldump指令实现数据备份.mysql指令实现数据还原 经常有朋友问我,DBA到底是做什么的,百科上说:数据库管理员(Databas ...

  7. 服务器访问数据库表mysql

    服务器的MySQL配置就不说了,直接说一些用到的基础命令 登陆 show databases; use 数据库: show tables; 执行sql即可: 一定要有分号 select * from ...

  8. 一个WordCount执行过程的实例

  9. 几何+map套set——cf1163C

    能灵活用map+set的组合就能过这题了 /* 分成三个步骤来做: 1.通过点两两构造线 by=ax+c,先求a,b,再求c,用gcd(d,b)简化 2.线去重:用map+pair 3.统计交点 */ ...

  10. js算法之寻路

    A*寻路算法 算法流程说明: 说明:起始节点记作S,目标节点记作E,对于任意节点P,从S到当前节点P的总移动消耗记作GP,节点P到目标E的曼哈顿距离记作HP,从节点P到相邻节点N的移动消耗记作DPN, ...