Flask Web Development – An Introduction

Flask websites are built using the Flask microframework. Wikipedia defines Flask as one of many “minimalistic web application frameworks.” In this article I will be giving an introduction to Flask web development, along with resources to get started developing with the flask framework.

What makes Flask web development so magical?

The Flask microframework is backed by Python. Python is a very stable, powerful, aged and most importantly… Legible programming language. So legible in fact, I usually forego code comments.

For example, writing the comment:

For each user in the followers list, display the user’s name

above this ↓
for user in followers:
print user.name
serves no purpose. In fact, it makes my code harder to scan through later on. Which brings me to my next key point…

Websites built in Flask are scalable

Scalability is defined by the effort it takes to come back to a site and build from it at a later point in time. The Flask web framework allows you to build sites kind of like lego blocks. You mix and match and install only the modules you need using pip.

Python code is easy to read and write

Due to the legibility of Python, Flask websites becomes much more easy to structure. You could start with a simple app and not have to worry about coming back to it months from now to extend it’s functionality. It’s amazing how easy it is to pick up where you left off in Python programming. Therefore, allowing websites written in Flask to achieve the same benefit.

Flask for Web Development and Web Apps

Flask utilizes simple routing, paired with a great templating engine and a built-in local server for rapid design and development.
App structure is as basic or complex as needed.

For example, a basic Flask web app or website is laid out as follows:

  • app
    • /static
    • /templates
    • __init__.py

Flask website folder structure

The Static folder is for images, stylesheets, sass/ stylus files, and other static media required for your site.

The Templates folder holds pieces of the website such as the header, sidebar, content, menu, forms and footer. Template files aren’t necessary, however they do provide greater organization and more of a manageable site structure.

init.py can be named other things such as app.py or name.py. This file contains the code necessary to launch the website or app. There is no mandatory naming convention for this file. This file is initialized with python typing python __init__.py in a terminal window. Depending on how you structured your app, it should start a local server with the following message returned:
* Running on

Recommended reading

Finally, here are a couple websites I recommend to get started with Flask web development:

  • flask.pocoo.org — Site created by Armin Ronacher (the creator of the Flask microframework). This site is a great resource to have when starting out when using Flask for web development. In other words, it will help teach you the foundations in flask web development, along with some more advanced features of the Flask web framework.
  • exploreflask.com — Founded from a Kickstarter campaign, this is an online guidebook for the Flask web framework. In addition, the Explore Flask website gives an introduction to common coding conventions, configuration, extensions, security, deployment and even some design tips. Most noteworthy, it’s a free online book and a great resource if you ever get stuck on something in your Flask development.

Furthermore, I will soon be publishing tutorials on the Flask microframework on this site.