Mastering Python: Part 4: As a Webserver (Flask)

Learning Python

Using Python

Mastering Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.

As a Webserver (Flask)

Python has some built-in modules for potentially working as a webserver. Starting with http, the http.server module can be used as a low-level web server for working with incoming requests.

However, while http.server can be used, it is not particularly efficient to “reinvent the wheel” when it comes to a very common problem. For that, there is the Flask external module.

Installing Flask

Assuming PIP is already installed and configured, Flask can be added through running the installation process.

pip install flask

Note Flask is installed as part of

Using Flask

Flask works on decorators associated with routes.

In HTTP terminology, a route is a possible URL path for accessing data. Flask is designed to be RESTful. That is, a URL route should be meaningful. Accessing a route such as “/user/<username” should be associated with data paired with the user and the specific username.

Play with the example on!