Book Image

Flask Blueprints

By : Joel Perras
Book Image

Flask Blueprints

By: Joel Perras

Overview of this book

Table of Contents (14 chapters)

Your first Flask application structure


The canonical Flask introductory application that is found on the official website is a paragon of simplicity, and is something you've most likely come across beforehand:

# app.py 
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
app.run()

The preceding application can be run by first installing the Flask package from pip (all in a virtual environment, of course) and then executing the script itself under the Python interpreter:

$ pip install Flask
$ python app.py

This will start the Werkzeug development web server, which was installed when Flask was obtained via pip, and serve the application on http://localhost:5000 by default.

The typical way in which people start a new Flask application is to add various endpoints to the incredibly simple module that we showed in the preceding section:

from flask import Flask, request
app = Flask(__name__)


@app.route("/")
def hello...