assert warning clarification and adding blueprint containers to app object

This commit is contained in:
narzeja 2016-10-16 06:48:49 +02:00
parent 4f86cad66e
commit b19452a1a7
2 changed files with 6 additions and 4 deletions

View File

@ -5,7 +5,7 @@ from sanic.response import json, text
app = Sanic(__name__)
blueprint = Blueprint('name', url_prefix='/my_blueprint')
blueprint2 = Blueprint('name2', url_prefix='/my_blueprint2')
blueprint2 = Blueprint('name', url_prefix='/my_blueprint2')
@blueprint.route('/foo')

View File

@ -21,6 +21,8 @@ class Sanic:
self.config = Config()
self.request_middleware = []
self.response_middleware = []
self.blueprints = {}
self._blueprint_order = []
# -------------------------------------------------------------------- #
# Registration
@ -94,9 +96,9 @@ class Sanic:
"""
if blueprint.name in self.blueprints:
assert self.blueprints[blueprint.name] is blueprint, \
'A blueprint\'s name collision occurred between %r and ' \
'%r. Both share the same name "%s". ' % \
(blueprint, self.blueprints[blueprint.name], blueprint.name)
'A blueprint with the name "%s" is already registered. ' \
'Blueprint names must be unique.' % \
(blueprint.name,)
else:
self.blueprints[blueprint.name] = blueprint
self._blueprint_order.append(blueprint)