Flask_Session1
Flask_Session1
• Flask Installation
• Virtual Environment
• Flask Basics
• Basic Routes
• Dynamic Routing
• Debug Mode
2
Flask Overview
Let's imagine you visit a website written with Flask
1. Accept Information
from the user.
2. Retrieve Information
from a database.
Front End
3. Create / Update /
Delete / information in
database.
You
4. Display information
back to the user.
4
Flask Overview
To perform these tasks, we'll need a web framework to accept and return
information with the front-end.
Flask
Front End
Web App
You
5
Flask Overview
Flask is the web framework that allows us to connect python code to the web.
Flask
Front End
Web App
You
6
Flask Overview
We'll use Flask and Python to connect to HTML templates and retrieve, edit, or
return statements.
Flask
Front End
Web App
You
7
Flask Overview
Accepting User Information
Forms
Flask
Front End
Web App
You
Database
SQLite 8
Flask Overview
Create / Read / Update / Delete Information from the database if necessary.
CRUD
Forms
Flask
Front End
Web App
You
Database
SQLite 9
Flask Overview
Then we'll want to return or display information back to the user.
CRUD
Forms
Flask
Front End
Web App
You
Database
SQLite 10
Flask Overview
We'll use Jinja Templates to grab information from Python and Flask to send info
back as HTML. CRUD
Forms
Flask
Front End
Web App
You
Database
SQLite 11
Flask Overview
This is a very high-level overview! There are many more possibilities: Payments,
Rest APIs, etc... CRUD
Forms
Flask
Front End
Web App
You
Database
SQLite 12
Flask Overview
o CSS
o BOOTSTRAP
13
Flask Overview
• Python is the coding language that allows us to use the Flask Web
Framework.
• Flask renders HTML templates, can edit them with Jinja, and
can communicate with a database through the use of libraries
such as SQLAlchemy (Flask - SQLAlchemy).
14
Flask Installation
• Install flask using pip. Open CMD and type the following
command.
15
Virtual Environment
• Imagine you're launched your web application and you use some
external python library.
• Then that library gets updated to a newer version, the update has
new features, but also has breaking changes.
16
Virtual Environment
17
Virtual Environment
VIRTUAL ENV
• This activates your virtual environment. Now you can install necessary
packages.
19
Flask Basics
20
Basic Routes
• We just saw how to create a web application with a single page
(returned in the form of string.)
21
Basic Routes
• Currently our homepage or domain is locally represented as
http://127.0.0.1:5000
22
Dynamic Routing
• Often we will want URL route extensions to be dynamic based on
the situation.
• For example we may want a page per user, so that the extension is
in the form:
• www.site.com/user/unique_user_name
• To achieve this effect we can use dynamic routes
24
Debug Mode
25
Routing Exercise
26
Routing Exercise
27
Routing Exercise
28
Thank You