python flask tutorial
TRANSCRIPT
-
8/20/2019 Python Flask Tutorial
1/2
Python Web Frameworks:
Django, Flask, Pyramid, Tornado, Bottle, Diesel, Pecan, Falcon
Flask:
Two external libraries:Werkzeug – Toolkit or W!"# $!tandard Pyt%on #nterace between &''lication and !er(er)*inja+ – Tem'late ngine $-enders tem'lates)
Advantages:
. asy to learn / im'lement
. "ood documentation
Installation:
'i' install Flask
Minimal Application:
rom lask im'ort Flaska'' 0 Flask $11name11)
2a''3route $454)de %ello $454):
return 46ello World74
i 11name11 00 411main114a''3run $)
What we did above?
. #m'orted Flask class
. 8reated a single module instance 411name114
. 9sed 4route4 decorator to tell w%at url s%ould trigger our 4%ello4 unction
. Deined a 4%ello4 unction $also %el'ul in generating t%e url later using url1or)
. 9sed 4run4 unction to run t%e local ser(er
Debug Mode:
a''3run $debug 0 True)
rl !uilding:
url1or$ 4unction1name4 ) generates t%e url corres'onding to t%e unction1name
rl Methods:
2b'3route $ 45login4, met%ods 0 4P;!T4, 4"T4, 4D
-
8/20/2019 Python Flask Tutorial
2/2
rom lask im'ort Blue'rintb' 0 Blue'rint$4b'4, 11name11)g3 a''3register1blue'rint$b', url1'reix045cat.ui4)>a''ends cat.ui 'reix to all urls w%ile generating t%emurl1or$ 4b'3unction1name4 )
Why !lueprints?
. !u''orting common 'atterns t%roug%out t%e a''lication
. -egister deault 'reixes in a''lication url
. Pro(ide tem'late ilters, static iles, etc3
Demo:
. ?inimal &''lication
. Text box or sub.category c%ange
. ;(er(iew o Product 8atalog Tagging
Moving ahead with Pymongo:
. @addTo!et $To a''end a new item in a list o (alue o a ield)
. @grou' $&ggregates documents by desired key (alues)
. @matc% $?atc%es aggregated documents o(er a constraint)
. @'roject $"enerates desired names or Aueries)
"e#erences:
%tt':55lask3'ocoo3org5docs53C5Auickstart5>
%tt':55o'entec%sc%ool3git%ub3io5'yt%on.lask5
http://flask.pocoo.org/docs/0.10/quickstart/http://opentechschool.github.io/python-flask/http://opentechschool.github.io/python-flask/http://flask.pocoo.org/docs/0.10/quickstart/