Python製Webフレームワークの設計と実装 / How to develop web application framework in Python
by
MASASHI Shibata
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Masashi Shibata / 2016.04.30 / #kosenconf C-BATA PRESENTS Python8FCϑϨʔϜϫʔΫͷݪཧͱ࣮
Slide 2
Slide 2 text
Masashi Shibata @c_bata_ WEB ENGINEER ໌ੴߴઐ / Pythonista
Slide 3
Slide 3 text
Handling Request from Clients kobin WEB SERVER WEB APPLICATION REQUEST RESPONSE
Slide 4
Slide 4 text
Handling Request from Clients kobin WEB SERVER WEB APPLICATION REQUEST RESPONSE
Slide 5
Slide 5 text
WSGI ʲ Web Server Gateway Interfaceʳ <֓ཁ> PythonͰ࡞ΔWebΞϓϦέʔγϣϯͷ ࣮ํ๏ͷඪ४Խ༷ PEP3333
Slide 6
Slide 6 text
༷ ᶃ ͭͷҾΛ࣋ͬͨݺͼग़͠ՄೳͳΦϒδΣΫτ ᶄ ୈҾͱͯ͠͞ΕͨΦϒδΣΫτΛݺͼग़͠ )551εςʔλείʔυͱϔομใΛ͢ ᶅ ϨεϙϯεϘσΟͱͯ͠όΠτจࣈྻΛZJFME͢Δ JUFSBCMFΛฦ͢ IUUQTXXXQZUIPOPSHEFWQFQTQFQ
Slide 7
Slide 7 text
def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] Hello World with just 3 lines of Python
Slide 8
Slide 8 text
def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] ͭͷҾΛ࣋ͬͨ ݺͼग़͠ՄೳͳΦϒδΣΫτ
Slide 9
Slide 9 text
def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] εςʔλε ϔομใ ୈҾ
Slide 10
Slide 10 text
def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] ϨεϙϯεϘσΟ όΠτྻ
Slide 11
Slide 11 text
$ gunicorn -w 1 filename:app [2016-04-15 10:17:00 +0900] [1873] [INFO] Starting gunicorn 19.4.5 [2016-04-15 10:17:00 +0900] [1873] [INFO] Listening at: http://127.0.0.1:8000 (1873) [2016-04-15 10:17:00 +0900] [1873] [INFO] Using worker: sync [2016-04-15 10:17:00 +0900] [1878] [INFO] Booting worker with pid: 1878 WSGI SERVER Enable the use of any framework with any server.
Slide 12
Slide 12 text
ͲΜͳػೳ͕ඞཁʁ
Slide 13
Slide 13 text
Function 1 ROUTING ϧʔςΟϯά ࠓͲ͜ʹΞΫηεͯ͠l)FMMP8PSMEz
Slide 14
Slide 14 text
Function 2 HTML TEMPLATE HTMLςϯϓϨʔτ ࠓϓϨʔϯςΩετฦͯ͠Δ͚ͩ
Slide 15
Slide 15 text
Function 3 STATIC FILES ੩తϑΝΠϧ ຊ൪Ͱ/HJOYͱ͔ͬͯฦ͚͢Ͳɺ։ൃதʜ $44 +4 ը૾Λ͍͍ײ͡ʹฦͯ͠ཉ͍͠
Slide 16
Slide 16 text
Function 4 REQUEST OBJECT ϦΫΤετΦϒδΣΫτ ࠓͨͩͷࣙॻܕΦϒδΣΫτ͕͞ΕͯΔ͚ͩ ͍͍ײ͡ʹϥοϓͯ͘͠ΕΔΦϒδΣΫτ͕΄͍͠
Slide 17
Slide 17 text
Function 5 RESPONSE OBJECT ϨεϙϯεΦϒδΣΫτ εςʔλεͱ͔ϔομใͱ͔Λ͍͍ײ͡ʹίϯτϩʔϧ
Slide 18
Slide 18 text
a small and statically-typed web framework kobin https://github.com/c-bata/kobin
Slide 19
Slide 19 text
from kobin import Kobin app = Kobin() @app.route(‘^/$') def hello(): return "Hello World!!" if __name__ == '__main__': app.run()
Slide 20
Slide 20 text
IUUQHJUIVCDPNDCBUBLPCJOFYBNQMF DEMO TODOΞϓϦ [ Kobin + Angular2 ]
Slide 21
Slide 21 text
Kobin is readable (maybe). 84(*ͱ͔1ZUIPOͷจ๏ͷཧղඞཁ ࠓͷͱ͜Ζߦ͙Β͍ 5ZQF)JOUJOH 3PVUJOHͷลΓ͔ΒಡΉͷ͕͍͍͔ ! ! ! !
Slide 22
Slide 22 text
3FGFSFODFT • Documentations • https://kobin.readthedocs.org/ja/latest/ • https://kobin.readthedocs.org/en/latest/ • Kobin Example • https://github.com/c-bata/kobin-example • https://kobin.herokuapp.com/
Slide 23
Slide 23 text
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ THANK YOU