Having just completed the basic introduction to Python in the Flatiron school curriculum, I'm excited to get into Flask to understand how the framework can aid my back-end development. Lets talk a little bit about what Flask is, why engineers are using it, and why I'm excited to jump in and learn it.
Flask is a lightweight framework written in python that is used to create fast, flexible web applications. Flask does not require any additional specific tools or libraries, has no database abstraction or form validations. This makes Flask a very popular and useful tool for beginner Python engineers as well as seasoned vets.
Flask is known as a WSGI (pronounced 'whiskey') framework. WSGI stands for Web Server Gateway Interface. This framework is, essentially, a way for web servers to pass information to web applications. Since this is an "out of the box" framework, you can jump straight in and start with minimal setup and integration. This is one of the major draws for Flask over larger frameworks.
Some other ticks in the Pro column for Flask:
Scalability - Flask can handle a large number of requests, and can modularize your code base to allow multiple developers to work on discreet, independent parts of the application.
Flexibility - Flask can integrate with several other tools and libraries. Flasks simplicity allows the developer to easily rearrange and move code around.
Easy to Understand - It can't be overstated how impactful it is for an engineer to be able to jump in and start coding. Flask is easy to negotiate and engineers can focus on getting coding quickly without getting bogged down in setup and learning the framework.
Documentation - The healthy number of examples and tips arranged in a structured manner encourages developers to use the framework, as they can easily get introduced to the different aspects and capabilities of the tool.
Installing flask
The following distributions will be installed when you install Flask:
Werkzeug implements WSGI, the standard Python interface between applications and servers.
Jinja is a template language that renders the pages your application serves.
MarkupSafe comes with Jinja. It escapes untrusted input when rendering templates to avoid injection attacks.
ItsDangerous securely signs data to ensure its integrity. This is used to protect Flask’s session cookie.
Click is a framework for writing command line applications. It provides the
flask
command and allows adding custom management commands.
Create a project folder with a .venv folder contained within
$ mkdir myproject $ cd myproject $ python3 -m venv .venv
Activate the virtual environment
$ . .venv/bin/activate
Within the active virtual env, install Flask
$ pip install Flask
Example
A simple app that prints out the statement "Hello World!"
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"