Introduction

What is Flask?

Flask is a micro-framework for the web, written in Python.

Micro because the basis for its functionality is extremely limited, in spite of its numerous extensions.

Used for creating websites and APIs.

Flask is based on the projects Werkzeug and Jinja 2.

Why use Flask?

  • Easy to learn.

  • Pythonic (adopts the principles and style of programming from Python).

  • Small/light but scalable for big applications.

  • Decorator defined routes

Development

Environment creation

$ mkdir project
$ cd project
$ mkdir static
$ mkdir templates
$ touch app.py
$ chmod +x app.py
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install Flask

Routing/Redirect

Static

Files in the static directory are served directly (without the need for any code):

  • Useful to place images, JavaScript, CSS, etc.

Jinja2 templates

hello.html

users.html

HTTP methods

Receive a file through a POST request

Last updated