Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Introduction to Flask
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Sébastien Fievet
February 23, 2017
Technology
72
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Flask
Workshop given for a Swisscom Digital Lab meetup at EPFL
Sébastien Fievet
February 23, 2017
More Decks by Sébastien Fievet
See All by Sébastien Fievet
Django Round-Up – Meetup Django CH #28
zyegfryed
0
68
Django Round-Up – Meetup Django CH #25
zyegfryed
0
61
Django Round-Up – Meetup Django CH #23
zyegfryed
0
59
Django Round-Up – Meetup Django CH #21
zyegfryed
0
77
Django Round-Up – Meetup Django CH #20
zyegfryed
0
84
Django Round-Up – Meetup Django CH #19
zyegfryed
2
93
[Django] URL prefix with runserver
zyegfryed
0
1.5k
[Django] Generating PDF with PDFForm
zyegfryed
0
94
[Django] RESTful API
zyegfryed
1
230
Other Decks in Technology
See All in Technology
作り直せるコードは迅速に 作り直せないDBは慎重に - AI時代のプロダクトエンジニアが「判断の不可逆性」で開発速度を変える話
kinosuke01
0
300
Reactの設計論
uhyo
14
7.6k
2026_devsumi_ozono.pdf
o3
2
150
AIとペアプロを始める。人とのペアプロをやめる。ペアプロの良さを改めて知る。もっと好きになった。 / Rediscovering Pair Programming
honyanya
1
330
リージョンの壁を越える、 ちょっと変わったAWSサービスの話
falken
PRO
1
300
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
4
360
2026/09/10 Spring Bootから Jakarta EE/MicroProfileへの移行
megascus
0
300
V8コントリビュート超入門
riyaamemiya
0
160
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
150
GuardDuty 検知対応を DevOps Agent で効率化しようとしている話 / GuardDuty Investigations with DevOps Agent
masahirokawahara
1
350
module Synths; end
asonas
1
130
こんなアーキテクチャ図は嫌だ BEYOND THE TIME: 半年後の自分へ贈る15のメッセージ / 15 of Anti-pattern in AWS Architecture Diagrams
naospon
3
300
Featured
See All Featured
Speed Design
sergeychernyshev
33
2.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Facilitating Awesome Meetings
lara
57
7.1k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
480
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
GraphQLとの向き合い方2022年版
quramy
50
15k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Chasing Engaging Ingredients in Design
codingconduct
0
300
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
780
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
520
Transcript
Introduction to Flask Sébastien Fievet Swisscom Digital Lab at EPFL
Prerequisites
$ python --version Python 2.7.12 https://www.python.org/downloads
$ pip --version pip 9.0.1 https://pip.pypa.io/en/stable/installing/
$ pip install virtualenv $ virtualenv --version 13.1.2 https://virtualenv.pypa.io/en/stable/installation/
$ git clone \ https://github.com/zyegfryed/intro_to_flask.git $ cd intro_to_flask $ virtualenv
.venv $ source .venv/bin/activate
Hello Flask!
–Deny “What… Why Flask?”
–http://flask.pocoo.org/ “Flask is a microframework for Python based on Werkzeug,
Jinja 2 and good intentions.”
Diving In https://github.com/zyegfryed/intro_to_flask/tree/01_intro
$ pip install Flask http://flask.pocoo.org/docs/0.12/installation/
# app.y from flask import Flask app = Flask(__name__) @app.route('/')
def hello_world(): return 'Hello, World!'
$ git checkout 01_intro $ export FLASK_APP=app.py $ flask run
$ curl http://127.0.0.1:5000/ Hello, World!
Chatbot
Diving In https://github.com/zyegfryed/intro_to_flask/tree/02_chatbot
$ pip install fbmessenger https://github.com/rehabstudio/fbmessenger
# app.py @app.route('/webhook', methods=['GET', 'POST']) def webhook(): if request.method ==
'GET': if request.args.get('hub.verify_token') == \ os.environ.get('FB_VERIFY_TOKEN'): return request.args.get('hub.challenge') raise ValueError('FB_VERIFY_TOKEN does not match.')
# app.py @app.route('/webhook', methods=['GET', 'POST']) def webhook(): […] elif request.method
== 'POST': messenger.handle(request.get_json(force=True)) return ''
# app.py from fbmessenger import BaseMessenger from fbmessenger import elements
class Messenger(BaseMessenger): def message(self, message): element = elements.Text('Received: {0}’.format( message['message']['text'])) self.send(element.to_dict()) […]
# app.py messenger = \ Messenger(os.environ.get(‘FB_PAGE_TOKEN’))
$ ngrok --version ngrok version 2.1.18 https://ngrok.com/download
Messenger https://developers.facebook.com/docs/messenger- platform/guides/setup
$ git checkout 02_chatbot $ export FB_VERIFY_TOKEN=… $ export FB_PAGE_TOKEN=…
$ flask run - - - - - - - - - — - - - - - - - - - - - - $ ngrok http 5000
Async
Diving In https://github.com/zyegfryed/intro_to_flask/tree/03_async
# app.py from redis import StrictRedis redis = StrictRedis() @job('default',
connection=redis) def messenger_handle(message): messenger.handle(message) @app.route('/webhook', methods=['GET', 'POST']) def webhook(): […] elif request.method == 'POST': messenger_handle.delay(request.get_json(force=True)) return ''
$ redis-server --version Redis server v=3.2.8 https://redis.io/download
$ pip install rq http://python-rq.org/
$ git checkout 03_async $ export FB_PAGE_TOKEN=… $ rqworker default
- - - - - - - - - — - - - - - - - - - - - - $ redis-server
Links • https://github.com/zyegfryed/intro_to_flask • https://www.python.org/downloads/ • https://pip.pypa.io/en/stable/installing/ • http://flask.pocoo.org/ •
http://flask.pocoo.org/docs/0.12/quickstart/ • https://developers.facebook.com/docs/messenger-platform/guides/setup • https://github.com/rehabstudio/fbmessenger • https://redis.io/download • http://python-rq.org/ • https://github.com/rehabstudio/fbmessenger