shownb / shownb.github.com

shownb.github.io
shownb.github.io
5 stars 1 forks source link

bottle的基本运行原理&&bottle快速入门总结 #8

Open shownb opened 7 years ago

shownb commented 7 years ago

bottle的基本运行原理

*分析基于0.4.10 一般python框架应该按照一下原则来处理

  1. 建立起一个wsgi服务器.
  2. 接受来自用户的扔过来的两个东西environ和start_response
  3. 自己根据environ里面的web路径和请求的参数,设置start_response.
  4. 返回信息

框架基本是对第3步进行处理。

ROUTES_SIMPLE和ROUTES_REGEXP列表数据来自哪里? 由装饰器route生成

def route(url, **kargs):
    def wrapper(handler):
        add_route(url, handler, **kargs)
        return handler
    return wrapper

bottle 源码解析 http://liaoph.com/python-bottle/

bottle 源码分析 https://hexiangyu.me/posts/18/

Bottle 总结 http://roseou.github.io/2016/03/27/bottle/

全栈python http://fullstackpython.atjiang.com/bottle.html

Bottle-0.13 文档中文 https://my.oschina.net/zzir/blog/683569

bottle笔记 https://www.kancloud.cn/yubang/bottle

bottle开发的一个样板 https://help.zendesk.com/hc/en-us/articles/229488948-Building-a-custom-ticket-form-with-the-Zendesk-API

bottle快速入门总结

  1. cookie可以通过request.cookies.get访问

  2. HTTP头可以通过request.headers.get访问 request.headers.get('X-Requested-With')

  3. 表单可以用下面的方式获取

属性 GET Form fields POST表单数据 File Uploads
BaseRequest.query yes no no
BaseRequest.forms no yes no
BaseRequest.files no no yes
BaseRequest.params yes yes no
BaseRequest.GET yes no no
BaseRequest.POST no yes yes

from bottle import Bottle from two import two_app

app = Bottle() app.mount("/two", two_app)

@app.get("/") def index(): return "主模块"

if name == "main": app.run(host="127.0.0.1", port=8000, reloader=True, debug=True)

two.py
```python
# coding:UTF-8

from bottle import Bottle

two_app = Bottle()

@two_app.get("/")
def index():
    return "第二个模块"

项目结构参考 https://github.com/inkenkun/bottle_mvc https://github.com/vladimirprieto/bottle-mvc-mongodb https://github.com/salimane/bottle-mvc

flask的一些装饰器 http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/

自己动手写orm https://yanxurui.cc/posts/python/write-my-own-orm/ 廖雪峰的orm https://github.com/michaelliao/awesome-python-webapp/blob/day-03/www/transwarp/orm.py 廖雪纺的orm py3 https://github.com/michaelliao/awesome-python3-webapp/blob/day-03/www/orm.py

理解 Python 装饰器看这一篇就够了 https://foofish.net/python-decorator.html

Effective Python https://guoruibiao.gitbooks.io/effective-python/content/

深入理解元类 http://blog.jobbole.com/21351/

怎么理解阻塞非阻塞与同步异步的区别 https://www.zhihui.com/question/19732473

A Web Crawler with asyncio Coroutines http://drafts.damnever.com/2015/A-Web-Crawler-With-asyncio-Coroutines.html

最新python异步编程详解 http://www.jianshu.com/p/b036e6e97c18

python中的生成器和协程 https://www.bwangel.me/2016/08/05/python中的生成器和协程/

用 Python 实现生成 QR 二维码 https://juejin.im/entry/577cca197db2a20054f008e4

简化markdown写作中的贴图流程 http://weishu.me/2015/10/16/simplify-the-img-upload-in-markdown/

从 asyncio 简单实现看异步是如何工作的 https://ipfans.github.io/2016/02/simple-implement-asyncio-to-understand-how-async-works/