July 2019
Beginner to intermediate
302 pages
9h 38m
English
The following is an example of a simple Hello World application using Blueprint. It will work in a manner similar to the previous recipe but is much more modular and extensible.
First, we will start with the following flask_app/my_app/__init__.py file:
from flask import Flask from my_app.hello.views import hello app = Flask(__name__) app.register_blueprint(hello)
Next, the views file, my_app/hello/views.py, which should look as follows:
from flask import Blueprint from my_app.hello.models import MESSAGES hello = Blueprint('hello', __name__) @hello.route('/') @hello.route('/hello') def hello_world(): return MESSAGES['default'] @hello.route('/show/<key>') def get_message(key): return MESSAGES.get(key) or "%s not found!" % key ...Read now
Unlock full access