Created
October 21, 2019 21:37
-
-
Save s-maj/191e8bb929a42b25edbfd7fad23d8c07 to your computer and use it in GitHub Desktop.
blueprint group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sanic import Blueprint | |
from sanic import Sanic | |
from sanic.response import text | |
bp1 = Blueprint('bp1', url_prefix='/bp1') | |
bp2 = Blueprint('bp2', url_prefix='/bp2') | |
@bp1.middleware('request') | |
async def bp1_only_middleware(request): | |
print('applied on Blueprint : bp1 Only') | |
@bp1.route('/') | |
async def bp1_route(request): | |
return text('bp1') | |
@bp2.route('/<param>') | |
async def bp2_route(request, param): | |
return text(param) | |
group = Blueprint.group(bp1, bp2) | |
@group.middleware('request') | |
async def group_middleware(request): | |
print('common middleware applied for both bp1 and bp2') | |
app = Sanic(__name__) | |
app.blueprints(group) | |
app.run(debug=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment