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

Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelClaus Ibsen
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaEdureka!
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 formsEyal Vardi
 
SQLAlchemy Primer
SQLAlchemy PrimerSQLAlchemy Primer
SQLAlchemy Primer泰 増田
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentationToufiq Mahmud
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsTessa Mero
 
Integrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesIntegrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesClaus Ibsen
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 

What's hot (20)

Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
SQLAlchemy Primer
SQLAlchemy PrimerSQLAlchemy Primer
SQLAlchemy Primer
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Php
PhpPhp
Php
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Integrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesIntegrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetes
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 

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

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
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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 educationjfdjdjcjdnsjd
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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...Drew Madelung
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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 RobisonAnna Loughnan Colquhoun
 

Recently uploaded (20)

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
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 
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...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 

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