assert warning clarification and adding blueprint containers to app object
This commit is contained in:
parent
4f86cad66e
commit
b19452a1a7
|
@ -5,7 +5,7 @@ from sanic.response import json, text
|
||||||
|
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
blueprint = Blueprint('name', url_prefix='/my_blueprint')
|
blueprint = Blueprint('name', url_prefix='/my_blueprint')
|
||||||
blueprint2 = Blueprint('name2', url_prefix='/my_blueprint2')
|
blueprint2 = Blueprint('name', url_prefix='/my_blueprint2')
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/foo')
|
@blueprint.route('/foo')
|
||||||
|
|
|
@ -21,6 +21,8 @@ class Sanic:
|
||||||
self.config = Config()
|
self.config = Config()
|
||||||
self.request_middleware = []
|
self.request_middleware = []
|
||||||
self.response_middleware = []
|
self.response_middleware = []
|
||||||
|
self.blueprints = {}
|
||||||
|
self._blueprint_order = []
|
||||||
|
|
||||||
# -------------------------------------------------------------------- #
|
# -------------------------------------------------------------------- #
|
||||||
# Registration
|
# Registration
|
||||||
|
@ -94,9 +96,9 @@ class Sanic:
|
||||||
"""
|
"""
|
||||||
if blueprint.name in self.blueprints:
|
if blueprint.name in self.blueprints:
|
||||||
assert self.blueprints[blueprint.name] is blueprint, \
|
assert self.blueprints[blueprint.name] is blueprint, \
|
||||||
'A blueprint\'s name collision occurred between %r and ' \
|
'A blueprint with the name "%s" is already registered. ' \
|
||||||
'%r. Both share the same name "%s". ' % \
|
'Blueprint names must be unique.' % \
|
||||||
(blueprint, self.blueprints[blueprint.name], blueprint.name)
|
(blueprint.name,)
|
||||||
else:
|
else:
|
||||||
self.blueprints[blueprint.name] = blueprint
|
self.blueprints[blueprint.name] = blueprint
|
||||||
self._blueprint_order.append(blueprint)
|
self._blueprint_order.append(blueprint)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user