flask一次request请求过程 基于tag0.1
来源:互联网 发布:sql删除语句 编辑:程序博客网 时间:2024/06/16 17:53
以下是基于flask@0.1(从最简单的开始)
前提:
flask是一个web app,它是跟wsgi_server交互的。他们之间的关系就不在这里叙述了详情请看 WSGI接口
从这里开始:
def wsgi_app(self, environ, start_response): """The actual WSGI application. This is not implemented in `__call__` so that middlewares can be applied: app.wsgi_app = MyMiddleware(app.wsgi_app) :param environ: a WSGI environment :param start_response: a callable accepting a status code, a list of headers and an optional exception context to start the response """ with self.request_context(environ): rv = self.preprocess_request() if rv is None: rv = self.dispatch_request() response = self.make_response(rv) response = self.process_response(response) return response(environ, start_response)
_request_ctx_stack.push(self)
2.request开始处理前,看看有没有需要预处理的func(通过@before_request修饰器的函数)
for func in self.before_request_funcs: rv = func()
3.由url找到对应endpoint,并从route表找到对应的view_function对该request进行处理,如果发生exception,就交给对应的errorhandler进行处理
def dispatch_request(self): """ try: endpoint, values = self.match_request() return self.view_functions[endpoint](**values) except HTTPException, e: handler = self.error_handlers.get(e.code) if handler is None: return e return handler(e) except Exception, e: handler = self.error_handlers.get(500) if self.debug or handler is None: raise return handler(e)
response = self.make_response(rv)
5.进行response
return response(environ, start_response)这里主要是由werkzeug库中的Response内处理,调用BaseResponse类的__call__函数跟wsgi app进行交互
最后:
在函数wsgi_app()结束之后,_request_ctx_stack会pop出在栈顶的元素
总结:
总结:
本文章比较简单,并没有介绍Request和Response这两个主要的处理类。只是大概说了一下request响应的大体流程。在flask0.1的时候flask还是比较简单,单个文件,跟bottle类似。
0 0
- flask一次request请求过程 基于tag0.1
- flask一次request请求过程 基于tag0.2和0.3
- flask一次request请求过程 基于tag0.7
- gunicorn分析 基于 tag0.2
- Http 一次请求过程
- 一次HTTP请求过程
- SpringMVC一次请求过程
- 浅谈一次URL请求过程
- Python Flask Web 第八课 —— request 请求对象
- Flask源码解读 <2> --- 请求上下文和request对象
- 用flask开发个人博客(2)—— Flask中的请求对象request
- 一次完整的Http请求过程
- 一次完整的http请求过程
- Struts2完成一次请求的过程
- 一次完整的Http请求过程
- 一次完整的Http请求过程
- QEEPHP一次完整请求的过程(转)
- Servlet一次请求和响应过程
- OJ提交题目中的语言选项里G++与C++的区别
- rman备份出现ORA-19625
- FLV学习(四)FlvParser源码阅读(2)相关的数据结构
- JDBC--实例代码
- Spring Boot 注解启动的两种方式
- flask一次request请求过程 基于tag0.1
- 2. Add Two Numbers
- whole-genome-sequencing Data Analysis 学习笔记3: 测试数据及参考基因组的准备
- sql条件查询
- python virtualenv flask
- 如何写好 Git commit messages
- js建造者模式
- java安全架构____java DSA数字签名原理
- 【Codeforces 776 C Molly's Chemicals】+ 前缀和 + map