SlideShare a Scribd company logo
IMPORT FLASK
AN INTRODUCTION TO PYTHON’S FRIENDLY
NEIGHBOURHOOD WEB MICROFRAMEWORK.
NEIL GREY
NEIL@COMBOMASH.COM
COMBOMASH ENTERTAINMENT
AGENDA
❖ INTRODUCTIONS
❖ GETTING STARTED
❖ OVERVIEW OF PYTHON & MVC
❖ WHY FLASK?
❖ HELLO WORLD!
❖ ROUTING
❖ TEMPLATES
❖ INTERACTIVE COMPONENTS
❖ FORMS, REQUESTS, & AJAX
❖ DATABASE INTEGRATION (SQLITE)
❖ LOGGING IN / SESSIONS
❖ EMAIL SUPPORT
INTRODUCTIONS
❖ WHO’S THE LOUD GUY UP FRONT?
❖ PROFESSIONAL PROGRAMMER AT MID-SIZED VISUAL EFFECTS &
GAMING COMPANIES FOR 6 YEARS
❖ HEAVY FOCUS ON SYSTEMS THAT PROMOTE EFFECTIVE
COMMUNICATION & EFFICIENT PROCESSES
❖ CYCLIST, BIKRAMITE, INDEPENDENT GAME DEVELOPER, OPEN-
SOURCE ENTHUSIAST, VEGAN, SELF-DIRECTED INVESTOR,
MARATHONER, BUSINESS OWNER
❖ BEEN WORKING WITH FLASK REGULARLY FOR JUST OVER A YEAR
AND WITH PYTHON FOR LAST 5 YEARS. EXPERIENCE IN WEB TECH
DATING BACK TO MID-90’S.
❖ ASK THE AUDIENCE
❖ WHAT’S YOUR NAME
& WHY ARE YOU HERE TODAY?
❖ EXPERIENCE LEVEL IN PYTHON? WEB DEVELOPMENT?
nataliedeemachine.com
GETTING STARTED
❖ OVERVIEW OF PYTHON & MVC
❖ WHY FLASK?
❖ HELLO WORLD!
❖ ROUTING
❖ TEMPLATES
LEARN PYTHON IN 10 MINUTES
HTTP://WWW.STAVROS.IO/TUTORIALS/PYTHON/
MODEL-VIEW-CONTROLLER (MVC)
❖ THE MODEL
❖ REPRESENTATION OF DATA. USUALLY HAS A STRONG RELATION WITH
THE UNDERLYING DATABASE.
❖ THE VIEW(S)
❖ WHAT IS SHOWN TO THE USER. CAN BE ANY KIND OF USER INTERFACE,
USUALLY HTML PAGES WITH JAVASCRIPT WHEN DEALING WITH THE
WEB.
❖ THE CONTROLS
❖ WHAT OPERATIONS ARE DONE ON THE DATA.
A CLEAN & CONVENIENT WAY TO DESIGN SOFTWARE PROJECTS
INVOLVING USER INTERFACES WHICH PRESENT AND MANIPULATE SETS
OF DATA.
WHY FLASK?
❖ SMALL : QUICK TO LEARN AND MASTER
❖ COMPLETE : YOU CAN USE TO DO SERIOUS APPS
❖ LEAN : A SHELL AND A TEXT EDITOR ARE ENOUGH, NO NEED FOR A
CUMBERSOME IDE
❖ IT IS VERY WELL DOCUMENTED
❖ WHY USING A SCRIPTING LANGUAGE LIKE PYTHON FOR A WEB
APPLICATION?
❖ ADAPTED LANGUAGE WHICH EASILY SUPPORTS PASTING TOGETHER
VARIOUS COMPONENTS (DATABASE, RENDERING, ROUTING, . . . )
❖ MAKES ITS EASIER TO RELEASE EARLY & OFTEN (DEVOPS)
❖ EASIER TO MAINTAIN & MODIFY
❖ SPEED GOOD ENOUGH FOR MANY USE CASES
FLASK: HELLO WORLD!
• RUN SCRIPT VIA COMMAND-LINE: PYTHON RUN.PY
• GO TO: 127.0.0.1:5000 TO REVIEW
FLASK: ROUTING
Flask uses dynamic pathing to
match user requests to server-
side responses. This is in direct
contrast to a language like PHP
which primarily uses directory-
based pathing to locate files
containing called-upon
functionality.
This is extremely useful since we
can pass variables into our
dynamic paths so not to duplicate
functionality across multiple files,
and still have a human-readable
URL.
FLASK: ROUTING
Status Code Type
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
500 Internal Server Error
501 Not Implemented
503 Service Unavailable
There’s a lot to be said for graceful error handling, especially when it comes to publicly accessible
web sites. Flask lets you easily custom handle errors as well as throw them when needed.
FLASK: TEMPLATES
Templating keeps the logic of your web app separate from its layout and style. Ideally, we want to avoid
scenarios where we are processing any HTML within our main Python syntax.
VS
FLASK: TEMPLATES
Templating is handled by Jinja2, a python-esque framework that allows for control statements and loops to
be placed into HTML templates, but discourages full logic processing within HTML blocks.
In our current example, we are
passing 3 variables through
“render_template” on the Python
side: article_title, user, & posts.
If article_title is provided we prepend
it in the document header.
We also have a for loop that goes
through an array of posts, printing out
relevant information on each
iteration.
FLASK: TEMPLATES
We can use Jinja2's template inheritance feature, which allows us to move the parts of the page layout that
are common to all templates and put them in a base template from which all other templates are derived.
In this example we’ve split out the display of the
posts from the standardized outline of the page.
This makes it so that we won’t have to maintain
elements like the main menu across multiple files.
INTERACTIVE COMPONENTS
❖ FORMS, REQUESTS, & AJAX
❖ DATABASE INTEGRATION (SQLITE)
❖ LOGGING IN / SESSIONS
❖ EMAIL SUPPORT
❖ DEPLOYMENT
FORMS, REQUESTS, & AJAX
Let’s use the free drag-and-
drop library dropzone.js to
demo what processing a file
upload server-side would
look like.
BASIC DATABASE SETUP (SQLITE)
Let’s setup a super-basic plain-text
user database that we can then
integrate into a login form.
Usually we would integrate this with
the “flask_login” package, but for the
sake of simplicity we’re going about it
at a different approach.
SESSIONS / LOGGING IN
SESSIONS / LOGGING IN
This time around we throw
sqlite into the mix to check and
see if the user exists in the
database before setting the
session ‘logged_in’ variable.
EMAIL SUPPORT
To use flask-mail we need to import it
in our init and configure it with the
settings we seek.
Once we’re up and running there we
can call upon that functionality from
anywhere else in the application.
Thank You
We really appreciate you taking the time to join in on this Flask
workshop today! If you have any questions down the line, feel
free to contact me at neil@combomash.com
Over at ComboMash Entertainment, we’re launching a kickstarter
for a game where tiy ommand a crew of oil rigger mercenaries
tasked with acquiring rare resources from uncharted planets.
Build offensive towers to attack hordes of aliens in an ever
changing environment.
If you’d like follow along with our progress, join our mailing list at
http://www.hextraction.com
Our Kickstarter campaign will be launching on April 21st and we’d
love to have your support!
Many Thanks,
Neil Grey
neil@combomash.com

More Related Content

PPTX
Flask restfulservices
Marcos Lin
 
PDF
Python RESTful webservices with Python: Flask and Django solutions
Solution4Future
 
PDF
Rest in flask
Yehor Nazarkin
 
PDF
Flask - Backend com Python - Semcomp 18
Lar21
 
PDF
Filling the flask
Jason Myers
 
PDF
Rest api with Python
Santosh Ghimire
 
PDF
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Nina Zakharenko
 
PDF
Flask patterns
it-people
 
Flask restfulservices
Marcos Lin
 
Python RESTful webservices with Python: Flask and Django solutions
Solution4Future
 
Rest in flask
Yehor Nazarkin
 
Flask - Backend com Python - Semcomp 18
Lar21
 
Filling the flask
Jason Myers
 
Rest api with Python
Santosh Ghimire
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Nina Zakharenko
 
Flask patterns
it-people
 

What's hot (20)

PPTX
Flask – Python
Max Claus Nunes
 
PDF
Web develop in flask
Jim Yeh
 
PDF
Introduction to Flask Micro Framework
Mohammad Reza Kamalifard
 
PDF
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Innovecs
 
ODP
REST API Laravel
John Dave Decano
 
PDF
Eve - REST API for Humans™
Nicola Iarocci
 
PDF
Rest API using Flask & SqlAlchemy
Alessandro Cucci
 
PDF
Flask Basics
Eueung Mulyana
 
PDF
Django REST Framework
Load Impact
 
PPTX
RESTful API 제대로 만들기
Juwon Kim
 
PDF
Flask RESTful Flask HTTPAuth
Eueung Mulyana
 
PDF
Flask Introduction - Python Meetup
Areski Belaid
 
PDF
And now you have two problems. Ruby regular expressions for fun and profit by...
Codemotion
 
PDF
Datagrids with Symfony 2, Backbone and Backgrid
eugenio pombi
 
PDF
New Features in PHP 5.3
Bradley Holt
 
PDF
web2py:Web development like a boss
Francisco Ribeiro
 
PDF
PHP And Web Services: Perfect Partners
Lorna Mitchell
 
PDF
<img src="../i/r_14.png" />
tutorialsruby
 
PDF
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Flask – Python
Max Claus Nunes
 
Web develop in flask
Jim Yeh
 
Introduction to Flask Micro Framework
Mohammad Reza Kamalifard
 
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Innovecs
 
REST API Laravel
John Dave Decano
 
Eve - REST API for Humans™
Nicola Iarocci
 
Rest API using Flask & SqlAlchemy
Alessandro Cucci
 
Flask Basics
Eueung Mulyana
 
Django REST Framework
Load Impact
 
RESTful API 제대로 만들기
Juwon Kim
 
Flask RESTful Flask HTTPAuth
Eueung Mulyana
 
Flask Introduction - Python Meetup
Areski Belaid
 
And now you have two problems. Ruby regular expressions for fun and profit by...
Codemotion
 
Datagrids with Symfony 2, Backbone and Backgrid
eugenio pombi
 
New Features in PHP 5.3
Bradley Holt
 
web2py:Web development like a boss
Francisco Ribeiro
 
PHP And Web Services: Perfect Partners
Lorna Mitchell
 
<img src="../i/r_14.png" />
tutorialsruby
 
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Ad

Similar to BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY (20)

PPTX
Flask
Mamta Kumari
 
PDF
Python Web Applications With Flask Handon Your Flask Skills2024 Jeffrey Leon ...
keyroreagan
 
KEY
LvivPy - Flask in details
Max Klymyshyn
 
PDF
Flask intro - ROSEdu web workshops
Alex Eftimie
 
PPTX
Intro to flask
Mohamed Essam
 
PPTX
Intro to flask2
Mohamed Essam
 
PDF
Flask Web Development 1st Edition Miguel Grinberg
cjvsgfu2766
 
PPTX
Flask Application ppt to understand the flask
vijoho5545
 
PPTX
Flask and Introduction to web frameworks
dipendralfs
 
PDF
Quick flask an intro to flask
juzten
 
PDF
Tutorial Módulo 1 de Introdução com Flask
Vinícius Marques
 
KEY
PHP to Python with No Regrets
Alex Ezell
 
DOCX
Akash rajguru project report sem v
Akash Rajguru
 
PPT
Learn flask in 90mins
Larry Cai
 
PPTX
Flask-Python
Triloki Gupta
 
PDF
Kyiv.py #17 Flask talk
Alexey Popravka
 
PDF
How to Design a Great API (using flask) [ploneconf2017]
Devon Bernard
 
PDF
Python master class part 1
Chathuranga Bandara
 
PPTX
Building a local web application with Flask
Hoffman Lab
 
Python Web Applications With Flask Handon Your Flask Skills2024 Jeffrey Leon ...
keyroreagan
 
LvivPy - Flask in details
Max Klymyshyn
 
Flask intro - ROSEdu web workshops
Alex Eftimie
 
Intro to flask
Mohamed Essam
 
Intro to flask2
Mohamed Essam
 
Flask Web Development 1st Edition Miguel Grinberg
cjvsgfu2766
 
Flask Application ppt to understand the flask
vijoho5545
 
Flask and Introduction to web frameworks
dipendralfs
 
Quick flask an intro to flask
juzten
 
Tutorial Módulo 1 de Introdução com Flask
Vinícius Marques
 
PHP to Python with No Regrets
Alex Ezell
 
Akash rajguru project report sem v
Akash Rajguru
 
Learn flask in 90mins
Larry Cai
 
Flask-Python
Triloki Gupta
 
Kyiv.py #17 Flask talk
Alexey Popravka
 
How to Design a Great API (using flask) [ploneconf2017]
Devon Bernard
 
Python master class part 1
Chathuranga Bandara
 
Building a local web application with Flask
Hoffman Lab
 
Ad

Recently uploaded (20)

PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
GYTPOL If You Give a Hacker a Host
linda296484
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
Doc9.....................................
SofiaCollazos
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
Software Development Company | KodekX
KodekX
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
GYTPOL If You Give a Hacker a Host
linda296484
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 

BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY

  • 1. IMPORT FLASK AN INTRODUCTION TO PYTHON’S FRIENDLY NEIGHBOURHOOD WEB MICROFRAMEWORK. NEIL GREY [email protected] COMBOMASH ENTERTAINMENT
  • 2. AGENDA ❖ INTRODUCTIONS ❖ GETTING STARTED ❖ OVERVIEW OF PYTHON & MVC ❖ WHY FLASK? ❖ HELLO WORLD! ❖ ROUTING ❖ TEMPLATES ❖ INTERACTIVE COMPONENTS ❖ FORMS, REQUESTS, & AJAX ❖ DATABASE INTEGRATION (SQLITE) ❖ LOGGING IN / SESSIONS ❖ EMAIL SUPPORT
  • 3. INTRODUCTIONS ❖ WHO’S THE LOUD GUY UP FRONT? ❖ PROFESSIONAL PROGRAMMER AT MID-SIZED VISUAL EFFECTS & GAMING COMPANIES FOR 6 YEARS ❖ HEAVY FOCUS ON SYSTEMS THAT PROMOTE EFFECTIVE COMMUNICATION & EFFICIENT PROCESSES ❖ CYCLIST, BIKRAMITE, INDEPENDENT GAME DEVELOPER, OPEN- SOURCE ENTHUSIAST, VEGAN, SELF-DIRECTED INVESTOR, MARATHONER, BUSINESS OWNER ❖ BEEN WORKING WITH FLASK REGULARLY FOR JUST OVER A YEAR AND WITH PYTHON FOR LAST 5 YEARS. EXPERIENCE IN WEB TECH DATING BACK TO MID-90’S. ❖ ASK THE AUDIENCE ❖ WHAT’S YOUR NAME & WHY ARE YOU HERE TODAY? ❖ EXPERIENCE LEVEL IN PYTHON? WEB DEVELOPMENT? nataliedeemachine.com
  • 4. GETTING STARTED ❖ OVERVIEW OF PYTHON & MVC ❖ WHY FLASK? ❖ HELLO WORLD! ❖ ROUTING ❖ TEMPLATES
  • 5. LEARN PYTHON IN 10 MINUTES HTTP://WWW.STAVROS.IO/TUTORIALS/PYTHON/
  • 6. MODEL-VIEW-CONTROLLER (MVC) ❖ THE MODEL ❖ REPRESENTATION OF DATA. USUALLY HAS A STRONG RELATION WITH THE UNDERLYING DATABASE. ❖ THE VIEW(S) ❖ WHAT IS SHOWN TO THE USER. CAN BE ANY KIND OF USER INTERFACE, USUALLY HTML PAGES WITH JAVASCRIPT WHEN DEALING WITH THE WEB. ❖ THE CONTROLS ❖ WHAT OPERATIONS ARE DONE ON THE DATA. A CLEAN & CONVENIENT WAY TO DESIGN SOFTWARE PROJECTS INVOLVING USER INTERFACES WHICH PRESENT AND MANIPULATE SETS OF DATA.
  • 7. WHY FLASK? ❖ SMALL : QUICK TO LEARN AND MASTER ❖ COMPLETE : YOU CAN USE TO DO SERIOUS APPS ❖ LEAN : A SHELL AND A TEXT EDITOR ARE ENOUGH, NO NEED FOR A CUMBERSOME IDE ❖ IT IS VERY WELL DOCUMENTED ❖ WHY USING A SCRIPTING LANGUAGE LIKE PYTHON FOR A WEB APPLICATION? ❖ ADAPTED LANGUAGE WHICH EASILY SUPPORTS PASTING TOGETHER VARIOUS COMPONENTS (DATABASE, RENDERING, ROUTING, . . . ) ❖ MAKES ITS EASIER TO RELEASE EARLY & OFTEN (DEVOPS) ❖ EASIER TO MAINTAIN & MODIFY ❖ SPEED GOOD ENOUGH FOR MANY USE CASES
  • 8. FLASK: HELLO WORLD! • RUN SCRIPT VIA COMMAND-LINE: PYTHON RUN.PY • GO TO: 127.0.0.1:5000 TO REVIEW
  • 9. FLASK: ROUTING Flask uses dynamic pathing to match user requests to server- side responses. This is in direct contrast to a language like PHP which primarily uses directory- based pathing to locate files containing called-upon functionality. This is extremely useful since we can pass variables into our dynamic paths so not to duplicate functionality across multiple files, and still have a human-readable URL.
  • 10. FLASK: ROUTING Status Code Type 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 500 Internal Server Error 501 Not Implemented 503 Service Unavailable There’s a lot to be said for graceful error handling, especially when it comes to publicly accessible web sites. Flask lets you easily custom handle errors as well as throw them when needed.
  • 11. FLASK: TEMPLATES Templating keeps the logic of your web app separate from its layout and style. Ideally, we want to avoid scenarios where we are processing any HTML within our main Python syntax. VS
  • 12. FLASK: TEMPLATES Templating is handled by Jinja2, a python-esque framework that allows for control statements and loops to be placed into HTML templates, but discourages full logic processing within HTML blocks. In our current example, we are passing 3 variables through “render_template” on the Python side: article_title, user, & posts. If article_title is provided we prepend it in the document header. We also have a for loop that goes through an array of posts, printing out relevant information on each iteration.
  • 13. FLASK: TEMPLATES We can use Jinja2's template inheritance feature, which allows us to move the parts of the page layout that are common to all templates and put them in a base template from which all other templates are derived. In this example we’ve split out the display of the posts from the standardized outline of the page. This makes it so that we won’t have to maintain elements like the main menu across multiple files.
  • 14. INTERACTIVE COMPONENTS ❖ FORMS, REQUESTS, & AJAX ❖ DATABASE INTEGRATION (SQLITE) ❖ LOGGING IN / SESSIONS ❖ EMAIL SUPPORT ❖ DEPLOYMENT
  • 15. FORMS, REQUESTS, & AJAX Let’s use the free drag-and- drop library dropzone.js to demo what processing a file upload server-side would look like.
  • 16. BASIC DATABASE SETUP (SQLITE) Let’s setup a super-basic plain-text user database that we can then integrate into a login form. Usually we would integrate this with the “flask_login” package, but for the sake of simplicity we’re going about it at a different approach.
  • 18. SESSIONS / LOGGING IN This time around we throw sqlite into the mix to check and see if the user exists in the database before setting the session ‘logged_in’ variable.
  • 19. EMAIL SUPPORT To use flask-mail we need to import it in our init and configure it with the settings we seek. Once we’re up and running there we can call upon that functionality from anywhere else in the application.
  • 20. Thank You We really appreciate you taking the time to join in on this Flask workshop today! If you have any questions down the line, feel free to contact me at [email protected] Over at ComboMash Entertainment, we’re launching a kickstarter for a game where tiy ommand a crew of oil rigger mercenaries tasked with acquiring rare resources from uncharted planets. Build offensive towers to attack hordes of aliens in an ever changing environment. If you’d like follow along with our progress, join our mailing list at http://www.hextraction.com Our Kickstarter campaign will be launching on April 21st and we’d love to have your support! Many Thanks, Neil Grey [email protected]