Flask Tutorial

Flask is a lightweight web application framework written in Python.

Flask is based on the WSGI (Web Server Gateway Interface) and the Jinja2 template engine, designed to help developers create web applications quickly and easily.

Flask lets us quickly build websites, APIs, and backend services in Python.

Flask is suitable for small projects, API interfaces, and microservices.


Who should read this tutorial?

This tutorial is suitable for developers with a foundation in Python.

  • Beginners with Python basics who want to get started with web development
  • Developers who want to learn a lightweight framework and quickly build websites and APIs
  • Beginners starting from scratch, self-teaching backend programming
  • People who need to quickly develop small projects, APIs, and backend services
  • People who want to get into Python web development but don't want to learn a heavyweight framework

What you need to know before learning this tutorial

Before starting this tutorial, you need some basic web knowledge andPython 3.x Basic Tutorial。

  • Python basics: variables, loops, conditionals, functions, lists/dictionaries, module imports
  • Web Basics: HTTP Protocol, GET/POST Requests, URL, Port
  • Frontend basics: simple HTML and CSS is sufficient
  • Database basics: understanding basic CRUD with SQLite/MySQL

Your First Flask Program

The following Flask program will output 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

other extensions