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, aiming to help developers create web applications quickly and easily.

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

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


Who is this tutorial for?

This tutorial is suitable for developers with a basic knowledge of Python.

  • Beginners with a Python foundation who want to get started in web development.
  • Developers who want to learn a lightweight framework to quickly build websites and APIs.
  • Beginners making a career switch from zero foundation and self-studying 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 heavy frameworks.

What you need to know before starting this tutorial

Before learning this tutorial, you need to understand 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, Ports
  • Frontend basics: simple HTML and CSS is enough.
  • Database basics: understanding basic CRUD operations in SQLite/MySQL.

Your First Flask Program

The following Flask program will output Hello World on the 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