Day 5 - 編寫Web架構

來源:互聯網
上載者:User

標籤:python


代碼地址

https://github.com/michaelliao/awesome-python3-webapp/blob/day-05/www/coroweb.py


參數定義的順序必須是:必選參數、預設參數、可變參數、命名關鍵字參數和關鍵字參數。



先看懂整體架構,再看詳細實現


1.coroweb.py在client請求開始返回func(*args, **kw),然後編寫func(*args,**kw)處理

#比如get(‘/index‘)(func(*args, **kw))


2.middlewares=[logger_factory, response_factory]

init_jinja2(app, filters=dict(datetime=datetime_filter))


3.先看懂add_routes(app, ‘handlers‘),然後是add_static(app),最後await handler(request) 


add_route(app, handles.create_comment) 變成

# 自動把handler模組的所有合格函數註冊了:

add_routes(app, ‘handlers‘)


add_routes,handler->是否有index,blog等屬性


//不理解的 fn = getattr(mod, attr)

//到了add_route,變成了app.router.add_route(method, path, RequestHandler(app, fn))


4.最後的細節

func(*args, **kw)


if 全部都會執行


5.middlewares 攔截器

//await handler(request)


本文出自 “要有夢想,萬一實現了呢” 部落格,謝絕轉載!

Day 5 - 編寫Web架構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.