Press ESC to close

Python Flask – Introduction and Installation

Flask is a microframework for developing web applications using Python Programming Language.

Flask was created in 2010 by Armin Ronacher and is released under BSD license.

Flask is based on Werkzeug and Jinja2. Werkzeug enables Flask listen to and answer requests.

Jinja2 is a templating language and allows us pass data to our HTML user interface and perform basic expressions.

Most web frameworks do implement the MVC(Model View Controller) paradigm. However, as a micro-framework, Flask caters for the V(View) and C(Controller).

So Flask is leaving out M(Model) intentionally since it’s a micro-framework and aims to lean. The model is normally the data layer and Flask leaves you to choose a wealth of thrid-party extensions for yourself.

Flask wants to be as small and thin as possible so the feature set has to be limited. This makes Flask more unopinionated such that it caters for a wide variety of developers.

For instance with Flask, you can write a simple but fully working and deployable web app in a single file. Name the frameworks you know that can do that?

Fundamental Features Flask provides

As a Framework, Flask provides a set of libaries that provide generic solutions via various abstractions to ease our work as developers.

Some of these include:

Development Server and Debugger.

URL Routing.

Templating through Jinja2.

Sessions.

Cookies.

Request Handling.

Unicode Support.

These are just some and already provide us with powerful capabilities for making web applications.

For instance we can handle browser requests, route HTTP requests to controllers, manage sessions, handle Ajax requests and even evaluate Form data etc.

Features Flask leaves out

Flask, we said is a micro-framework so intentionally does not come bundled with all functionalities for instance other alternatives like Django normally include.

These features include:

Database integration.

Forms library.

Administration interface etc.

However, it is important to understand that each of these and other features can be installed via single three-word command.

We said Flask is based on Werkzeug and Jinja2. Let’s introduce the two.

What is Werkzeug ?

Werkzeug is a utility library for WSGI. WSGI stands for Web Server Gateway Interface and is a protocol for ensuring that:

A web application can communicate effectively with web server.

That web applications can work nicely together.

In short, WSGI is a python interface between web applications and a variety of servers for both development and deployment.

Installation

Flask is a python framework so first ensure that you have Python installed.

Flask requires Python 2.6 or newer.

Virtualenv

Virtualenv allows multiple side by side installations of Python one for each project.
It’s important to note that it doesn’t install separate copies of Python but has a way of keeping the projects isolated,

Installing Flask

Share Article:

When I was a 2nd year Software Engineering student, I buillt a now defunct online tool called Camposha(from Campus Share) using my then favorite language C#(ASP.NET) to compete OLX in my country(Kenya). The idea was to target campus students in Kenya. I got a few hundred signups but competing OLX proved too daunting. I decided to focus on my studies, learning other languages like Java,Python,Kotlin etc while meanwhile publishing tutorials at my YouTube Channel ProgrammingWizards TV which led to this site(camposha.info). Say hello or post me a suggestion: oclemmi@gmail.com .
Follow me below;
Github
, and on my channel:
ProgrammingWizards TV