Blueprints

A blueprint allows you to store related page handlers together. Let’s add the following URLs to our app: /account/create, /account/login, and /account/logout. The logical place to store the handlers for these URLs is in an account.py module.

Add the following lines to demo.py:

import account
app.register_blueprint(account.bp)

Create an account.py file with the following code:

from drakken.core import Blueprint
bp = Blueprint(name='account', url_prefix='/account')

@bp.route('/create')
def create(request, response):
    response.text = 'This is the create account page.'

@bp.route('/login')
def login(request, response):
    response.text = 'This is the login page.'

@bp.route('/logout')
def logout(request, response):
    response.text = 'This is the logout page.'

Launch the app and visit http://127.0.0.1:8000/account/login. You should see the message This is the login page.