What Is Flask?

Flask is a small and easy-to-extend, open-source Python micro-framework that lets you build web apps quickly.

Written by Sara A. Metwalli
Published on Dec. 19, 2022
What Is Flask?
Image: Shutterstock / Built In
Brand Studio Logo

Despite its simplicity, Flask has become a popular alternative to Django, which has a more complex structure and set of dependencies.

Flask vs. Django

Django is a more complex full-stack development framework so it requires some level of web development knowledge to use it. However, Flask is a simple WSGI (web server gateway interface) application, so if you know Python at all but have no web development experience, you can still use Flask to build web pages.


Is Flask Better Than Django? 

Some of the main differences between Flask and Django are that Flask supports API use while Django doesn’t. However, Django allows users to build dynamic HTML pages, while Flask doesn’t. Moreover, since Flask is a micro-framework, it allows for more freedom in the application writing style, whereas Django has a set writing style based on decisions made by Django developers. Some Flask applications can be as simple as one file of code, like the example below. 

Every Flask project consists of a simple, clear folder layout consisting of two main folders:

  • Flaskr: the directory containing the ode for the application.
  • Tests: the directory for the test modules.

Depending on your application and target platform, your project may contain other folders for version control information and virtual environment.

More From Sara A. Metwalli on Built InPseudocode: What It Is and How to Write It


Flask Examples

Let’s implement a simple “Hello World” web page using Flask. You’ll only need the following seven lines of code.

from flask import Flask
app = Flask(__name__)

def hello_world():
return ‘Hello World!’

if __name__ == ‘__main__’:

Building a simple “Hello World” web page in Flask is quite simple. Once you’ve got the Flask basics, you can work toward creating full-featured web applications including: 

  • A video chat application with Flask in its core that uses JavaScript and Twilio to work on all platforms, from a simple web browser to iOS and Android devices.
  • A Docker microservices that uses both Flask and React to help you understand the fundamentals of general web development, Flask and front-end development.
  • If you are a traveler, you can use Flask and Mapbox to make beautiful visualizations of your next trip.
  • If you’re planning a conference or an event, you can use Flask to implement a face recognition attendance system.
  • If you’re just getting started with programming, you can use Flask to build a simple email application.
Learn Flask for Python — Full Tutorial. | Video: freeCodCamp.org


Is Flask Hard to Learn?

The short answer is: no. Flask is a great place to start your Python web development journey. Flask documentation is extensive and easy to follow; it also has tutorials at all levels to help you get started, up skill and build real-world applications.

Moreover, the documentation contains information about the design process behind Flask and why the team made the decisions they did. Having this information will help you decide if you’d like to be part of the Flask project, in particular, or any of the Pocoo projects, in general.


A Brief History of Flask

Artmin Ronacher developed Flask. Ronacher is the leader of an international Python enthusiasts group called Pocoo. They based Flask on the Werkzeg WSGI toolkit and the Jinja2 template engine, which are also Pocoo projects. 

  • WSGI (Web Server Gateway Interface) is the commonly used Python web application development standard that defines the interactions between web servers and web applications.
  • Werkzeug is a toolkit that uses WSGI to implement, send requests and handle responses. 
  • Jinja2 is a Python web template that enables users to combine a template with a data source to render dynamic web pages.
Hiring Now
Cloud • Fintech • Other • Payments • Software • Data Privacy