Flask Tutorial
Flask is a lightweight Web application framework written in Python.
Flask is based on WSGI (Web Server Gateway Interface) and the Jinja2 template engine, and aims to help developers create Web applications quickly and easily.
Flask lets us quickly write websites, APIs, and backend services in Python.
Flask is suitable for small projects, API endpoints, and microservices.
Who should read this tutorial?
This tutorial is suitable for developers with a Python foundation.
- Beginners with a Python foundation who want to get started in Web development
- Developers who want to learn a lightweight framework and quickly write websites and APIs
- Beginners with no prior experience who are switching careers and teaching themselves backend programming
- People who need to rapidly develop small projects, APIs, and backend services
- People who want to get into Python Web development but do not want to learn a heavyweight framework
What you need to know before studying this tutorial
Before learning this tutorial, you need to understand some basic web knowledge and Python 3.x Basic Tutorial。
- Python basics: variables, loops, conditions, functions, lists and dictionaries, module imports
- Web basics: the HTTP protocol, GET/POST requests, URL, ports
- Frontend basics: simple HTML and CSS are sufficient
- Database basics: understanding basic CRUD operations in SQLite/MySQL
The first Flask program
The following Flask program outputs Hello World on a web page:
Example
from
flask
import
Flask
app
=
Flask
(
name
)
@
app.
route
(
"/"
)
def
hello
(
)
:
return
"Hello World!"
if
name
==
"main"
:
app.
run
(
)
Reference Documentation
- Flask official website:https://palletsprojects.com/projects/flask/
- Flask Chinese documentation:https://flask.palletsprojects.com/zh-cn/stable/
- Flask open-source repository:https://github.com/pallets/flask