Flask Setup (technical walkthrough)

Flask is a minimalist web framework. It helps the developer to build and maintain websites without having to reuse code or go to extra effort.

The key takeaway from that description is “minimalist”. Flask is quite powerful but doesn’t come overloaded with features out of the box. Taking advantage of its full potential requires turning to third party plugins and extensions.

Because of this, my advice is to use Flask (which I love) for simpler projects that only need a limited feature set. Anything more complicated, turn to Django.


This post is a technical walkthrough for setting up Flask on a Macbook Pro. It assumes you have already installed:

  1. Pip
  2. Virtualenv

Any line preceeded by a “$” is intended as a terminal command.

Lines to insert into files will be shown as a code snippet. For example:


line you should copy into file 

Anytime you see “project_name”, change it to the name of your project.


$ mkvirtualenv -p python3 project_name

$ pip install flask

$ pip freeze > requirements.txt

$ touch .gitignore



$ mkdir app

$ mkdir app/static

$ mkdir app/templates

$ mkdir app/templates/includes

$ touch run.py


import sys`
from app import app`

$ touch __init__.py


from flask import Flask
app = Flask(__name__)
from app import views
from app import filters

CSS and HTML Templates

$ touch app/static/styles.css

$ app/templates/base.html


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    {% block content %}
    {% endblock content %}

$ touch app/templates/index.html


{% extends "base.html" %}

{% block content %}
    <h1>Hello World</h1>
{% endblock content %} 

Routing URL’s

$ touch app/views.py


import os

from flask import render_template

from app import app

def index():
    return render_template("index.html")

$ touch app/filters.py


from app import app


$ pip install wtforms

$ pip freeze > requirements.txt

$ touch app/forms.py


from wtforms import Form, StringField, RadioField, validators, ValidationError

class FormName (Form):
    attribute1 = StringField ("Something", validators=[validators.DataRequired()])
    attribute2 = RadioField ( "Name",
        default = "option",
        choices = [
            ("choice1", "choice1",),
            ("choice2", "choice2",),