Flask+Python.pptx
Flask+Python.pptx
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Course Agenda
Flask Python
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to web frameworks
Here is an overview:
Consider that you are swiping down the feed on Instagram:
● With every swipe and refresh, the application (Instagram) will have to generate content based
on your interaction and activity in the app.
● It has to retrieve data from a couple of servers for querying, receiving and even data updation.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to web frameworks
Here is an overview:
● What if the app never had to do any real-time processing or data retrieval?
● It would be static and a lot simpler and faster to work with, correct?
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to web frameworks
There are two sides to a web application ecosystem:
Client-side Server-side
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to web frameworks
Quick look at the two sides:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to web frameworks
So, what is a web framework?
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to web frameworks
What about the coding?
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to Flask
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to Flask
What is Flask?
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to Flask
WSGI, Werkzeug and Jinja2?
● WSGI – Stands for Web Server Gateway Interface, it is used as a standard for the
creation of an interface between the server and the web application.
● Jinja2 – Jinja2 is a templating engine built for Python. It is popularly used to render
dynamic web pages.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to Flask
For what tasks would you use Flask?
● Jinja2 templating.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to Flask
Things to keep in mind when constructing an API for a web application:
● Users who register must be able to do tasks such as logging in, logging out and
editing some information on their profile.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to Flask
Prerequisites to learning and using Flask:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Installing Flask
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Installing Flask
Pretty simple steps:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Installing Flask
Verifying the installation:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Understanding Flask
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Understanding Flask
Debugging in Flask:
● After you have executed a sample piece of code, the development server will not be running
in the debug mode.
● Activating debug mode enables automatic reloading. Whenever changes are made to the
code, the server automatically reloads.
● It also activates the Python debugger to check on variables during the execution.
● To go into debug mode, stop the running server and run the following piece of code:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Understanding Flask
Using HTML templates
● A simple application only displays a message without using any HTML attributes.
● Almost all of the web apps use HTML to display information to the visitor.
● Flask provides a helper function called render_template() that allows the usage of the Jinja
template engine.
● Doing this will ensure that you can write HTML code in .html files and even write
functionality and logic of the application there too.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Understanding Flask
Setting up a database
● A database is required to store almost all the data that is used by the application.
● You can use many SQL databases and integrate it with sqlite3 module which can help you
interact with the database easily and readily.
● Data conversion from one format to the other would be required as the data is used in the
form of rows and columns in a database.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Flask vs Django
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Flask vs Django
1. Handling admin tasks:
Flask Django
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Flask vs Django
2. Template:
Flask Django
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Flask vs Django
3. Support for visual debugging:
Flask Django
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Flask vs Django
4. Development styles:
Flask Django
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Flask vs Django
5. Development styles:
Flask Django
Flask was built for rapid Django was built for easy and
prototyping and development. structured development.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Applications of Flask
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Applications of Flask
There are numerous examples:
● The website Pinterest is one of the largest social media sites in the world, the creator shared
that it was built using the Flask framework.
● Barack Obama’s 2012 presidential campaign site used Flask a the main web framework.
● Lyft is a very popular ride sharing app that uses a lot of frameworks to work but it is mainly
built around Flask.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Applications of Flask
Here are some of the companies that use Flask:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Advantages and
disadvantages of Flask
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Advantages and disadvantages of Flask
There are numerous advantages:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Advantages and disadvantages of Flask
There are numerous advantages:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Advantages and disadvantages of Flask
Here are some of the disadvantages:
● Setting up the environment for a large project requires a lot of previous experience.
● Flask does not provide any login mechanism or authentication like login by default.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Summary
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited