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 Repl.it

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 Repl.it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.