SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...Innovecs
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™Nicola Iarocci
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyAlessandro Cucci
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기Juwon Kim
 
Flask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthFlask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthEueung Mulyana
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python MeetupAreski Belaid
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...Codemotion
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3Bradley Holt
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a bossFrancisco Ribeiro
 
PHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersPHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersLorna Mitchell
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesRaimonds Simanovskis
 

La actualidad más candente (20)

Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
 
httpie
httpiehttpie
httpie
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemy
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기
 
Flask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthFlask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuth
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
 
PHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersPHP And Web Services: Perfect Partners
PHP And Web Services: Perfect Partners
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
 

Similar a BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY

How to – wrap soap web service around a database
How to – wrap soap web service around a databaseHow to – wrap soap web service around a database
How to – wrap soap web service around a databaseSon Nguyen
 
WebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureWebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureFrank Greco
 
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningFrequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningArul ChristhuRaj Alphonse
 
MuleSoft Online Meetup - MuleSoft integration with snowflake and kafka
MuleSoft Online Meetup - MuleSoft integration with snowflake and kafkaMuleSoft Online Meetup - MuleSoft integration with snowflake and kafka
MuleSoft Online Meetup - MuleSoft integration with snowflake and kafkaRoyston Lobo
 
How to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
How to best setup SharePoint 2013, Web Apps, Workflow Manager with PowershellHow to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
How to best setup SharePoint 2013, Web Apps, Workflow Manager with PowershellSamuel Zürcher
 
Normalizing x pages web development
Normalizing x pages web development Normalizing x pages web development
Normalizing x pages web development Shean McManus
 
Internationalizing The New York Times
Internationalizing The New York TimesInternationalizing The New York Times
Internationalizing The New York TimesScott Taylor
 
Experiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamExperiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamBrian Benz
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stackJohan Edstrom
 
Adobe Flash Platform for the Enterprise
Adobe Flash Platform for the EnterpriseAdobe Flash Platform for the Enterprise
Adobe Flash Platform for the EnterpriseMike Slinn
 
Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9sumsid1234
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2kaashiv1
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2kaashiv1
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The CloudAnna Brzezińska
 
Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Brian Ritchie
 

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

How to – wrap soap web service around a database
How to – wrap soap web service around a databaseHow to – wrap soap web service around a database
How to – wrap soap web service around a database
 
WebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureWebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the Future
 
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningFrequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
 
MuleSoft Online Meetup - MuleSoft integration with snowflake and kafka
MuleSoft Online Meetup - MuleSoft integration with snowflake and kafkaMuleSoft Online Meetup - MuleSoft integration with snowflake and kafka
MuleSoft Online Meetup - MuleSoft integration with snowflake and kafka
 
How to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
How to best setup SharePoint 2013, Web Apps, Workflow Manager with PowershellHow to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
How to best setup SharePoint 2013, Web Apps, Workflow Manager with Powershell
 
Normalizing x pages web development
Normalizing x pages web development Normalizing x pages web development
Normalizing x pages web development
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
CSG 2012
CSG 2012CSG 2012
CSG 2012
 
Internationalizing The New York Times
Internationalizing The New York TimesInternationalizing The New York Times
Internationalizing The New York Times
 
Experiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamExperiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure team
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stack
 
Adobe Flash Platform for the Enterprise
Adobe Flash Platform for the EnterpriseAdobe Flash Platform for the Enterprise
Adobe Flash Platform for the Enterprise
 
Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2
 
Ebook2
Ebook2Ebook2
Ebook2
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The Cloud
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011
 

Último

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY

  • 1. IMPORT FLASK AN INTRODUCTION TO PYTHON’S FRIENDLY NEIGHBOURHOOD WEB MICROFRAMEWORK. NEIL GREY NEIL@COMBOMASH.COM 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 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