SlideShare a Scribd company logo
1 of 16
Larry cai <larry.caiyu@gmail.com>
Agenda
 Introduction
 Exercise 1: Flask’s “Hello World”
 Exercise 2: Routing for URL
 Exercise 3:Template (Jinja2)
 Exercise 4: Handle form
 Exercise 5: Database (Flask-SQLAlchemy)
 Reference
Learn flask in 90 minutes2 04/13/15
http://flask.pocoo.org/
Environment Preparation (docker)
 Boot2docker Installer (127M)
 Contains latest docker already, fast
 Container persistence via disk automount on /var/lib/docker
 $ docker -v
 User/Passwd: docker/tcuser (192.168.59.103)
 Download python:2 docker image
 $ docker pull python:2
 (Windows/Mac) Clone the code from github to your user
directory (~/git)
https://github.com/larrycai/codingwithme-flask
 Notepad++ & MobaXterm are recommended
Learn flask in 90 minutes3 04/13/15
http://boot2docker.io/
Introduction
 Flask is a microframework for Python based on
Werkzeug, Jinja 2 and good intentions.
 Similar to Play framework (Java/Scala), Sinatra (Ruby),
 Also Django vs Ruby on Rails vs Grail ..
Learn flask in 90 minutes4 04/13/15
http://flask.pocoo.org/
Exercise 1: Hello World
 Run first app inside docker environment
$ cd /c/Users/<id>/git/codingwithme-flask
$ docker run -it -v $PWD:/code -w /code -p 5000:5000 python:2 bash
# pip install flask
# cd exer1
# python app.py
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
192.168.59.3 - - [08/Apr/2015 15:50:29] "GET / HTTP/1.1" 200 -
192.168.59.3 - - [08/Apr/2015 15:50:29] "GET /favicon.ico HTTP/1.1" 404
-
 Browse: http://192.168.59.103:5000
 Edit the app.py to print your name “Hello
Larry” instead of “Hello World”
 Tips: edit in windows, don’t need restart
(debug=True) Learn flask in 90 minutes5 04/13/15
Routing/Redirect for URL
 Routing is defined by the route() decorator
 Dynamic routing using variable
 Redirect to another one using redirect, url_for
Learn flask in 90 minutes6 04/13/15
Exercise 2: Routing
 Implement /user to suggest use /user/<name>
 Implement /user/<name>, say hello if it is Larry, otherwise
say byebye
 Redirect /users/ to /user with error indication
# cd ../exer2
# python app.py
 Tips: check console log redirect 302 (redirect)
Learn flask in 90 minutes7 04/13/15
Template using Jinja2
 Flask configures the Jinja2 template engine automatically
 render_template
 Jinja2 is a full featured template engine for Python. 
 Map python variable into template
 Template inheritance makes it possible to use the same
or a similar layout for all templates
Learn flask in 90 minutes8 04/13/15
http://jinja.pocoo.org/
Exercise 3: Jinja2 Template
 Use template instead of string for function hello_user()
# cd ../exer3
# python app.py
Learn flask in 90 minutes9 04/13/15
Handle form
 request.form is good enough for simple form
 Flask-WTF module can be used if needed complex
handling for the form (like validation)
Learn flask in 90 minutes10 04/13/15
Exercise 4: Web Form
 Provide form to user as started in user()
# cd ../exer4
# python app.py
 Check whether it is in allowed list and redirect to hello
page, otherwise show error message (“xxx, who bring
you here ?”)
 Tips: form is normal html form
Learn flask in 90 minutes11 04/13/15
Database ORM – Flask-SQLAlchemy
 Flask-SQLAlchemy is extension provides a wrapper
for the SQLAlchemy project, which is an Object
Relational Mapper or ORM
 Support different database (SQLite, MySQL, Postgre ….)
 Command Steps
 Define database
 The data model
 Create database
 Operate database ..
Learn flask in 90 minutes12 04/13/15
Exercise 5: ORM for Database
 Start with base comments app and understand
# cd ../exer5
# pip install flask-sqlalchemy
# python app.py
 Add extra item “nickname”
 Bonus:
Initialize the database (/create) if database doesn’t exist (remove
*.sqlite3 first)
Reset the database (/drop)
Tips:
db.create_all(app=app) & db.drop_all(app=app)
Learn flask in 90 minutes13 04/13/15
example is based on: http://runnable.com/UhcUVQ7XwdEqAAPg/using-
sqlalchemy-in-flask-for-python
Summary
 Flask is python web framework, similar exists in other
language
 Routing/Template/Form/Database are the base
knowledge.
 Simple but powerful (together with css/javascript)
 Learn more sample, and try to build your own !!
Learn flask in 90 minutes14 04/13/15
Reference
 http://flask.pocoo.org/
 Book: Flask Web Development:
http://oreilly.com/catalog/9781449372620/
 Miguel Grinberg’s Blog: http://blog.miguelgrinberg.com/
 Base example for exer5 :
http://runnable.com/UhcUVQ7XwdEqAAPg/using-sqlalchemy-
in-flask-for-python

Learn flask in 90 minutes15 04/13/15
ChangeLog
 2015/04/12: first release
 2015/04/13: after first pilot, summary is added
Learn docker in 90 minutes16 04/13/15

More Related Content

What's hot

Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask PresentationParag Mujumdar
 
스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해beom kyun choi
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.Mikhail Egorov
 
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 ThymeleafThymeleaf
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slidesmattysmith
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack IntroductionAnjali Chawla
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSRafael Casuso Romate
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJSAll Things Open
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsMikhail Egorov
 
Redux Toolkit & RTK Query in TypeScript: tips&tricks
Redux Toolkit & RTK Query in TypeScript: tips&tricksRedux Toolkit & RTK Query in TypeScript: tips&tricks
Redux Toolkit & RTK Query in TypeScript: tips&tricksFabio Biondi
 

What's hot (20)

Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Serving ML easily with FastAPI - meme version
Serving ML easily with FastAPI - meme versionServing ML easily with FastAPI - meme version
Serving ML easily with FastAPI - meme version
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
 
스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
 
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
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Fetch API Talk
Fetch API TalkFetch API Talk
Fetch API Talk
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slides
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJS
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Redux Toolkit & RTK Query in TypeScript: tips&tricks
Redux Toolkit & RTK Query in TypeScript: tips&tricksRedux Toolkit & RTK Query in TypeScript: tips&tricks
Redux Toolkit & RTK Query in TypeScript: tips&tricks
 

Viewers also liked

Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)Sian Lerk Lau
 
webアプリケーションフレームワークの話
webアプリケーションフレームワークの話webアプリケーションフレームワークの話
webアプリケーションフレームワークの話Yoshihiro Ura
 
Webアプリケーションフレームワーク flask
Webアプリケーションフレームワーク flaskWebアプリケーションフレームワーク flask
Webアプリケーションフレームワーク flaskXMLProJ2014
 
Flask入門
Flask入門Flask入門
Flask入門aoshiman
 
Writing your first web app using Python and Flask
Writing your first web app using Python and FlaskWriting your first web app using Python and Flask
Writing your first web app using Python and FlaskDanielle Madeley
 
Flask patterns
Flask patternsFlask patterns
Flask patternsit-people
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBNicola Iarocci
 

Viewers also liked (11)

Flask SQLAlchemy
Flask SQLAlchemy Flask SQLAlchemy
Flask SQLAlchemy
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
 
webアプリケーションフレームワークの話
webアプリケーションフレームワークの話webアプリケーションフレームワークの話
webアプリケーションフレームワークの話
 
Webアプリケーションフレームワーク flask
Webアプリケーションフレームワーク flaskWebアプリケーションフレームワーク flask
Webアプリケーションフレームワーク flask
 
Flask入門
Flask入門Flask入門
Flask入門
 
Writing your first web app using Python and Flask
Writing your first web app using Python and FlaskWriting your first web app using Python and Flask
Writing your first web app using Python and Flask
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
Flask勉強会その1
Flask勉強会その1Flask勉強会その1
Flask勉強会その1
 
Python and you
Python and youPython and you
Python and you
 
Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
 

Similar to Learn flask in 90mins

How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.DrupalCampDN
 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuHow To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuWirabumi Software
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-TranslatorDashamir Hoxha
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using dockerLarry Cai
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...Eric Smalling
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?Sergei Stryukov
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesGerald Villorente
 
Docker Introduction.pdf
Docker Introduction.pdfDocker Introduction.pdf
Docker Introduction.pdfOKLABS
 
ScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection7mind
 

Similar to Learn flask in 90mins (20)

Drupal development
Drupal development Drupal development
Drupal development
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.
 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuHow To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using docker
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Oracle applications 11i dba faq
Oracle applications 11i dba faqOracle applications 11i dba faq
Oracle applications 11i dba faq
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
 
Docker Introduction.pdf
Docker Introduction.pdfDocker Introduction.pdf
Docker Introduction.pdf
 
Phalcon - Giant Killer
Phalcon - Giant KillerPhalcon - Giant Killer
Phalcon - Giant Killer
 
ScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection
 

More from Larry Cai

Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLarry Cai
 
Learn jobDSL for Jenkins
Learn jobDSL for JenkinsLearn jobDSL for Jenkins
Learn jobDSL for JenkinsLarry Cai
 
Learn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90minsLearn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90minsLarry Cai
 
Learn ELK in docker
Learn ELK in dockerLearn ELK in docker
Learn ELK in dockerLarry Cai
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer TalkLarry Cai
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90minsLarry Cai
 
Build service with_docker_in_90mins
Build service with_docker_in_90minsBuild service with_docker_in_90mins
Build service with_docker_in_90minsLarry Cai
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutesLarry Cai
 
Learn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLearn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLarry Cai
 
Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with PythonLarry Cai
 
Jenkins Scriptler in 90mins
Jenkins Scriptler in 90minsJenkins Scriptler in 90mins
Jenkins Scriptler in 90minsLarry Cai
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesLarry Cai
 
Lead changes in software development
Lead changes in software developmentLead changes in software development
Lead changes in software developmentLarry Cai
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90minsLarry Cai
 
Practical way to experience of Specification by Example
Practical way to experience of Specification by ExamplePractical way to experience of Specification by Example
Practical way to experience of Specification by ExampleLarry Cai
 
Experience from specification_by_examples
Experience from specification_by_examplesExperience from specification_by_examples
Experience from specification_by_examplesLarry Cai
 
Write book in markdown
Write book in markdownWrite book in markdown
Write book in markdownLarry Cai
 
Continuous Integration Introduction
Continuous Integration IntroductionContinuous Integration Introduction
Continuous Integration IntroductionLarry Cai
 
Agile & ALM tools
Agile & ALM toolsAgile & ALM tools
Agile & ALM toolsLarry Cai
 

More from Larry Cai (19)

Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
Learn jobDSL for Jenkins
Learn jobDSL for JenkinsLearn jobDSL for Jenkins
Learn jobDSL for Jenkins
 
Learn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90minsLearn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90mins
 
Learn ELK in docker
Learn ELK in dockerLearn ELK in docker
Learn ELK in docker
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer Talk
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
Build service with_docker_in_90mins
Build service with_docker_in_90minsBuild service with_docker_in_90mins
Build service with_docker_in_90mins
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
Learn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLearn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutes
 
Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with Python
 
Jenkins Scriptler in 90mins
Jenkins Scriptler in 90minsJenkins Scriptler in 90mins
Jenkins Scriptler in 90mins
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutes
 
Lead changes in software development
Lead changes in software developmentLead changes in software development
Lead changes in software development
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
 
Practical way to experience of Specification by Example
Practical way to experience of Specification by ExamplePractical way to experience of Specification by Example
Practical way to experience of Specification by Example
 
Experience from specification_by_examples
Experience from specification_by_examplesExperience from specification_by_examples
Experience from specification_by_examples
 
Write book in markdown
Write book in markdownWrite book in markdown
Write book in markdown
 
Continuous Integration Introduction
Continuous Integration IntroductionContinuous Integration Introduction
Continuous Integration Introduction
 
Agile & ALM tools
Agile & ALM toolsAgile & ALM tools
Agile & ALM tools
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
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
 
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
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
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...
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
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?
 
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
 

Learn flask in 90mins

  • 2. Agenda  Introduction  Exercise 1: Flask’s “Hello World”  Exercise 2: Routing for URL  Exercise 3:Template (Jinja2)  Exercise 4: Handle form  Exercise 5: Database (Flask-SQLAlchemy)  Reference Learn flask in 90 minutes2 04/13/15 http://flask.pocoo.org/
  • 3. Environment Preparation (docker)  Boot2docker Installer (127M)  Contains latest docker already, fast  Container persistence via disk automount on /var/lib/docker  $ docker -v  User/Passwd: docker/tcuser (192.168.59.103)  Download python:2 docker image  $ docker pull python:2  (Windows/Mac) Clone the code from github to your user directory (~/git) https://github.com/larrycai/codingwithme-flask  Notepad++ & MobaXterm are recommended Learn flask in 90 minutes3 04/13/15 http://boot2docker.io/
  • 4. Introduction  Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.  Similar to Play framework (Java/Scala), Sinatra (Ruby),  Also Django vs Ruby on Rails vs Grail .. Learn flask in 90 minutes4 04/13/15 http://flask.pocoo.org/
  • 5. Exercise 1: Hello World  Run first app inside docker environment $ cd /c/Users/<id>/git/codingwithme-flask $ docker run -it -v $PWD:/code -w /code -p 5000:5000 python:2 bash # pip install flask # cd exer1 # python app.py * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 192.168.59.3 - - [08/Apr/2015 15:50:29] "GET / HTTP/1.1" 200 - 192.168.59.3 - - [08/Apr/2015 15:50:29] "GET /favicon.ico HTTP/1.1" 404 -  Browse: http://192.168.59.103:5000  Edit the app.py to print your name “Hello Larry” instead of “Hello World”  Tips: edit in windows, don’t need restart (debug=True) Learn flask in 90 minutes5 04/13/15
  • 6. Routing/Redirect for URL  Routing is defined by the route() decorator  Dynamic routing using variable  Redirect to another one using redirect, url_for Learn flask in 90 minutes6 04/13/15
  • 7. Exercise 2: Routing  Implement /user to suggest use /user/<name>  Implement /user/<name>, say hello if it is Larry, otherwise say byebye  Redirect /users/ to /user with error indication # cd ../exer2 # python app.py  Tips: check console log redirect 302 (redirect) Learn flask in 90 minutes7 04/13/15
  • 8. Template using Jinja2  Flask configures the Jinja2 template engine automatically  render_template  Jinja2 is a full featured template engine for Python.   Map python variable into template  Template inheritance makes it possible to use the same or a similar layout for all templates Learn flask in 90 minutes8 04/13/15 http://jinja.pocoo.org/
  • 9. Exercise 3: Jinja2 Template  Use template instead of string for function hello_user() # cd ../exer3 # python app.py Learn flask in 90 minutes9 04/13/15
  • 10. Handle form  request.form is good enough for simple form  Flask-WTF module can be used if needed complex handling for the form (like validation) Learn flask in 90 minutes10 04/13/15
  • 11. Exercise 4: Web Form  Provide form to user as started in user() # cd ../exer4 # python app.py  Check whether it is in allowed list and redirect to hello page, otherwise show error message (“xxx, who bring you here ?”)  Tips: form is normal html form Learn flask in 90 minutes11 04/13/15
  • 12. Database ORM – Flask-SQLAlchemy  Flask-SQLAlchemy is extension provides a wrapper for the SQLAlchemy project, which is an Object Relational Mapper or ORM  Support different database (SQLite, MySQL, Postgre ….)  Command Steps  Define database  The data model  Create database  Operate database .. Learn flask in 90 minutes12 04/13/15
  • 13. Exercise 5: ORM for Database  Start with base comments app and understand # cd ../exer5 # pip install flask-sqlalchemy # python app.py  Add extra item “nickname”  Bonus: Initialize the database (/create) if database doesn’t exist (remove *.sqlite3 first) Reset the database (/drop) Tips: db.create_all(app=app) & db.drop_all(app=app) Learn flask in 90 minutes13 04/13/15 example is based on: http://runnable.com/UhcUVQ7XwdEqAAPg/using- sqlalchemy-in-flask-for-python
  • 14. Summary  Flask is python web framework, similar exists in other language  Routing/Template/Form/Database are the base knowledge.  Simple but powerful (together with css/javascript)  Learn more sample, and try to build your own !! Learn flask in 90 minutes14 04/13/15
  • 15. Reference  http://flask.pocoo.org/  Book: Flask Web Development: http://oreilly.com/catalog/9781449372620/  Miguel Grinberg’s Blog: http://blog.miguelgrinberg.com/  Base example for exer5 : http://runnable.com/UhcUVQ7XwdEqAAPg/using-sqlalchemy- in-flask-for-python  Learn flask in 90 minutes15 04/13/15
  • 16. ChangeLog  2015/04/12: first release  2015/04/13: after first pilot, summary is added Learn docker in 90 minutes16 04/13/15