Django中的wsgi:application


  • 基本:
    •   uwsgi,uWSGI,WSGI三者关系

  •  Django中wsgi application 调用最终返回的是response,在上一篇中,我们在handler.run()函数---setup_environ()函数中,将request原始信息复制到wsgi.input中
    • 在回调函数的slef.request_class(env)会进一步封装成我们熟悉的request对象  
      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)
              response = self.get_response(request)
              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()),
              ]
              start_response(status, response_headers)
              if getattr(response, 'file_to_stream', None) is not None and environ.get('wsgi.file_wrapper'):
      
                  response.file_to_stream.close = response.close
                  response = environ['wsgi.file_wrapper'](response.file_to_stream, response.block_size)
      
              return respons

       


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM