A minimal Flask application looks something like this:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello World!"
A large Flask application can separate one file into multiple files by blueprints
.
Purpose
Make it easier for others to maintain the application.
Folder Structure of Large Application
/app
/templates
/static
/views
__init__.py
index.py
app.py
views/index.py
from flask import Blueprint, render_template
index_blueprint = Blueprint('index', __name__)
@index_blueprint.route("/")
def index():
return "Hello World!"
app.py
from flask import Flask
from views.index import index_blueprint
application = Flask(__name__)
application.register_blueprint(index_blueprint)
Run application
$ export FLASK_APP=app.py
$ flask run