SlideShare a Scribd company logo
1 of 73
Download to read offline
Web Develop in Flask 
Jim Yeh <lemonlatte@gmail.com>
Outline 
Introduce internet network 
What is HTTP request and response 
Flask 
Write a Todo list 
http://tinyurl.com/nccumath-flask
Internet 
People use browsers to surf the internet. 
You may hear that a server is crashed.
http://www………
Given a URL 
http://www.bing.com/search?q=math 
Protocol IP / Hostname Path Query String
HTTP Protocol 
A communication protocol 
A well-known client is web browser 
Not merely for browser
Request and Response 
Clients Servers 
Request 
Response
HTTP Request Methods 
GET 
POST
GET 
Browser a website by url 
Request resources (contents) 
Example: http://www.bing.com/search?q=math
POST 
Generally, we use it to submit a form 
Wrap data in request body
Response 
Roughly speaking, it is the contents on a browser.
IP / Hostname 
Address of a server 
You can register a Hostname (domain name) 
Hostname will be resolve to a IP address by DNS 
Where a request will be delivered to
Some Special IPs 
127.0.0.1 : loopback address 
0.0.0.0 : Network traffic from any valid IP address 
192.168.x.x : Preserved private IP address
Path 
Location of a file 
Purpose of your request
Query String 
Some information that you provided.
Server Side
Inspect Web Server 
Web Server 
(apache2, nginx) 
Python 
Web 
Application 
Request 
Request 
Object 
Response 
Response 
Object
Inspect Web Server 
Web Server 
(apache2, nginx) 
Python 
Web 
Application 
Request 
Request 
Object 
Response 
Response 
Object 
What we focus on
Web frameworks 
Django 
Flask 
Web.py 
Many…
Flask
Requirements 
python 
flask 
sqlalchemy
First App 
server.py
First App 
Create an app 
server.py
First App 
Create an app 
server.py 
Enable Debug Mode
First App 
Create an app 
Assign path 
server.py 
Enable Debug Mode
First App 
Create an app 
Assign path 
server.py 
Enable Debug Mode 
View function
First App 
Create an app 
Assign path 
View function 
Start the server 
server.py 
Enable Debug Mode
First App 
server.py
Run 
python server.py
Inspect Web Application 
Request 
Object 
Response 
Python Web Application Object
Inspect Web Application 
Request 
Object 
Response 
Object 
Dispatch path 
Run View Function 
Return value(string)
What’s different between this 
and traditional web pages?
Interact with end-users
Case 1 : Say Hi 
Hi, Jim
Use GET 
http://localhost:5000/?name=Jim 
Use query string in your view function
Exercise I 
Given a dictionary: 
{“apple”: “a fruit”, “calculus”: “a subject”, … and more} 
Query it by GET method 
Display “Not found” if the key is unavailable
Exercise I.I 
Design a web app that accept multiple query strings.
Once the length of return string 
becomes longer and longer...
The function is not readable
Is there a way to move 
contents out?
Is there a way to move 
contents out? 
A: Use Template (jinja2)
Create a templates 
<= Very important 
Create a “templates” folder 
Create a txt file (hello.txt) in templates folder 
Write contents in this file
Use template in view function 
from flask import render_template 
render_template(“hello.txt”)
Not merely a text
Format your content using 
HTML
HTML/HTML5 
A markup language 
Contents of a web page
A HTML Element 
<tag_name attr1=“value” attr2=“value”> content 
</tag_name> 
<p> This is a book </p> 
<h1> This a title </h1>
Some Elements 
<p> … </p> 
<h1> … <h1> to </h5> … </h5> 
<div> … </div> 
<ul> 
<li> item </li> 
<li> item </li> 
</ul> 
<ol> 
<li> item </li> 
<li> item </li> 
</ol>
HTML Layout
HTML Layout 
HTML Block
HTML Layout 
HTML Block 
Head
HTML Layout 
HTML Block 
Head 
Body
HTML Layout 
templates/ 
index.html
Rewrite hello function 
Again, use the 
HTML template 
that you just finished.
What about variables?
What about variables? 
A: Code in Template
Variable Substitution 
You can substitute variables in template files 
{{ name }} in HTML template
Transfer variables to template 
Use keyword arguments in render_template 
render_template(“hi.html”, name=name)
For, If Statement 
{% if name == “Jim” %} …… {% endif %} 
{% for item in things %} {% endfor %}
Case Study: Food List 
Display a list of your favorite food if it is public 
Otherwise, display a message
More syntax 
http://jinja.pocoo.org/docs/dev/templates
Exercise II 
Rewrite your dictionary app by HTML template.
Submit a Form
HTML Form 
Form elements 
form - a block of a form 
input - input fields 
label - label for an input
Case: Who are you? 
Ask for a name 
Once a name is submitted, Display the welcome message.
HTML for whoareyou 
Where the 
form request to 
Method for the 
form request
view function for whoareyou 
Allow method for POST 
Handle POST 
request 
Handle GET 
request
Exercise III: Calculator 
Two input fields and a submit 
Display the result
To-Do List
Views 
List all items 
Add a new item 
Delete an item
Flask redirect 
redirect 
url_for
Save to file 
Use pickle module (pickle.load and pickle.dump) 
pickle.load(open(“todo_list.data”, “r”)) 
pickle.dump(dictionary, open(“todo_list.data”, “r”))
Questions

More Related Content

What's hot

What's hot (20)

Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
 
Web api
Web apiWeb api
Web api
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Powershell Demo Presentation
Powershell Demo PresentationPowershell Demo Presentation
Powershell Demo Presentation
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
OAuth2 and Spring Security
OAuth2 and Spring SecurityOAuth2 and Spring Security
OAuth2 and Spring Security
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Express js
Express jsExpress js
Express js
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Introduction to Django Rest Framework
Introduction to Django Rest FrameworkIntroduction to Django Rest Framework
Introduction to Django Rest Framework
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 

Viewers also liked

Flask - Python microframework
Flask - Python microframeworkFlask - Python microframework
Flask - Python microframework
André Mayer
 
Flask admin vs. DIY
Flask admin vs. DIYFlask admin vs. DIY
Flask admin vs. DIY
dokenzy
 
Django para portais de alta visibilidade. tdc 2013
Django para portais de alta visibilidade.   tdc 2013Django para portais de alta visibilidade.   tdc 2013
Django para portais de alta visibilidade. tdc 2013
Bruno Rocha
 
Coderfaire Data Networking for Developers
Coderfaire Data Networking for DevelopersCoderfaire Data Networking for Developers
Coderfaire Data Networking for Developers
Jason Myers
 

Viewers also liked (20)

Flask - Python microframework
Flask - Python microframeworkFlask - Python microframework
Flask - Python microframework
 
Flask admin vs. DIY
Flask admin vs. DIYFlask admin vs. DIY
Flask admin vs. DIY
 
Flask vs. Django
Flask vs. DjangoFlask vs. Django
Flask vs. Django
 
Mozcation Seattle 2011
Mozcation Seattle 2011Mozcation Seattle 2011
Mozcation Seattle 2011
 
Build and Deploy a Python Web App to Amazon in 30 Mins
Build and Deploy a Python Web App to Amazon in 30 MinsBuild and Deploy a Python Web App to Amazon in 30 Mins
Build and Deploy a Python Web App to Amazon in 30 Mins
 
Python web frameworks
Python web frameworksPython web frameworks
Python web frameworks
 
What The Flask? and how to use it with some Google APIs
What The Flask? and how to use it with some Google APIsWhat The Flask? and how to use it with some Google APIs
What The Flask? and how to use it with some Google APIs
 
Django para portais de alta visibilidade. tdc 2013
Django para portais de alta visibilidade.   tdc 2013Django para portais de alta visibilidade.   tdc 2013
Django para portais de alta visibilidade. tdc 2013
 
Diabetes and Me: My Journey So Far
Diabetes and Me: My Journey So FarDiabetes and Me: My Journey So Far
Diabetes and Me: My Journey So Far
 
Fuga dalla Comfort Zone
Fuga dalla Comfort ZoneFuga dalla Comfort Zone
Fuga dalla Comfort Zone
 
Filling the flask
Filling the flaskFilling the flask
Filling the flask
 
CoderDojo Romagna
CoderDojo RomagnaCoderDojo Romagna
CoderDojo Romagna
 
Quattro passi tra le nuvole (e non scordate il paracadute)
Quattro passi tra le nuvole (e non scordate il paracadute)Quattro passi tra le nuvole (e non scordate il paracadute)
Quattro passi tra le nuvole (e non scordate il paracadute)
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1
 
Intro python-object-protocol
Intro python-object-protocolIntro python-object-protocol
Intro python-object-protocol
 
Python Static Analysis Tools
Python Static Analysis ToolsPython Static Analysis Tools
Python Static Analysis Tools
 
Introduction to SQLAlchemy and Alembic Migrations
Introduction to SQLAlchemy and Alembic MigrationsIntroduction to SQLAlchemy and Alembic Migrations
Introduction to SQLAlchemy and Alembic Migrations
 
Online / Offline
Online / OfflineOnline / Offline
Online / Offline
 
Coderfaire Data Networking for Developers
Coderfaire Data Networking for DevelopersCoderfaire Data Networking for Developers
Coderfaire Data Networking for Developers
 
RESTful Web API and MongoDB go for a pic nic
RESTful Web API and MongoDB go for a pic nicRESTful Web API and MongoDB go for a pic nic
RESTful Web API and MongoDB go for a pic nic
 

Similar to Web develop in flask

10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
GiyaShefin
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat
Jonathan Linowes
 
LA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: FundamentalsLA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: Fundamentals
Thinkful
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
Tony Frame
 

Similar to Web develop in flask (20)

flask.pptx
flask.pptxflask.pptx
flask.pptx
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
 
introduction_php.ppt
introduction_php.pptintroduction_php.ppt
introduction_php.ppt
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat
 
(LA 1/16/18) Intro to JavaScript: Fundamentals
(LA 1/16/18) Intro to JavaScript: Fundamentals(LA 1/16/18) Intro to JavaScript: Fundamentals
(LA 1/16/18) Intro to JavaScript: Fundamentals
 
1/16/18 Intro to JS Workshop
1/16/18 Intro to JS Workshop1/16/18 Intro to JS Workshop
1/16/18 Intro to JS Workshop
 
LA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: FundamentalsLA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: Fundamentals
 
CS1520 Session 2 - Simple Router
CS1520 Session 2 - Simple RouterCS1520 Session 2 - Simple Router
CS1520 Session 2 - Simple Router
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Tf ffccjs
Tf ffccjsTf ffccjs
Tf ffccjs
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
Tf ffccjs
Tf   ffccjsTf   ffccjs
Tf ffccjs
 
Tf frccjs
Tf frccjsTf frccjs
Tf frccjs
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
httpie
httpiehttpie
httpie
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 

More from Jim Yeh (6)

Write FB Bot in Python3
Write FB Bot in Python3Write FB Bot in Python3
Write FB Bot in Python3
 
Introduction openstack horizon
Introduction openstack horizonIntroduction openstack horizon
Introduction openstack horizon
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python Class
 

Recently uploaded

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Web develop in flask