本文整理匯總了Python中flask.Flask.blueprints方法的典型用法代碼示例。如果您正苦於以下問題:Python Flask.blueprints方法的具體用法?Python Flask.blueprints怎麽用?Python Flask.blueprints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask.Flask
的用法示例。
在下文中一共展示了Flask.blueprints方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register_module
# 需要導入模塊: from flask import Flask [as 別名]
# 或者: from flask.Flask import blueprints [as 別名]
def register_module(self, module, **options):
"""Registers a module with this application. The keyword argument
of this function are the same as the ones for the constructor of the
:class:`Module` class and will override the values of the module if
provided.
.. versionchanged:: 0.7
The module system was deprecated in favor for the blueprint
system.
"""
assert blueprint_is_module(module), 'register_module requires ' \
'actual module objects. Please upgrade to blueprints though.'
if not self.enable_modules:
raise RuntimeError('Module support was disabled but code '
'attempted to register a module named %r' % module)
else:
from warnings import warn
warn(DeprecationWarning('Modules are deprecated. Upgrade to '
'using blueprints. Have a look into the documentation for '
'more information. If this module was registered by a '
'Flask-Extension upgrade the extension or contact the author '
'of that extension instead. (Registered %r)' % module),
stacklevel=2)
self.register_blueprint(module, **options)
示例2: register_blueprint
# 需要導入模塊: from flask import Flask [as 別名]
# 或者: from flask.Flask import blueprints [as 別名]
def register_blueprint(self, blueprint, **options):
"""Registers a blueprint on the application.
.. versionadded:: 0.7
"""
first_registration = False
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". Blueprints that ' \
'are created on the fly need unique names.' % \
(blueprint, self.blueprints[blueprint.name], blueprint.name)
else:
self.blueprints[blueprint.name] = blueprint
first_registration = True
blueprint.register(self, options, first_registration)
示例3: create_global_jinja_loader
# 需要導入模塊: from flask import Flask [as 別名]
# 或者: from flask.Flask import blueprints [as 別名]
def create_global_jinja_loader(self):
"""Creates the loader for the Jinja2 environment. Can be used to
override just the loader and keeping the rest unchanged. It's
discouraged to override this function. Instead one should override
the :meth:`jinja_loader` function instead.
The global loader dispatches between the loaders of the application
and the individual blueprints.
.. versionadded:: 0.7
"""
return DispatchingJinjaLoader(self)
示例4: modules
# 需要導入模塊: from flask import Flask [as 別名]
# 或者: from flask.Flask import blueprints [as 別名]
def modules(self):
from warnings import warn
warn(DeprecationWarning('Flask.modules is deprecated, use '
'Flask.blueprints instead'), stacklevel=2)
return self.blueprints
示例5: _next_blueprint_name
# 需要導入模塊: from flask import Flask [as 別名]
# 或者: from flask.Flask import blueprints [as 別名]
def _next_blueprint_name(blueprints, basename):
"""Returns the next name for a blueprint with the specified base name.
This method returns a string of the form ``'{0}{1}'.format(basename,
number)``, where ``number`` is the next non-negative integer not
already used in the name of an existing blueprint.
For example, if `basename` is ``'personapi'`` and blueprints already
exist with names ``'personapi0'``, ``'personapi1'``, and
``'personapi2'``, then this function would return ``'personapi3'``. We
expect that code which calls this function will subsequently register a
blueprint with that name, but that is not necessary.
`blueprints` is the list of blueprint names that already exist, as read
from :attr:`Flask.blueprints` (that attribute is really a dictionary,
but we simply iterate over the keys, which are names of the
blueprints).
"""
# blueprints is a dict whose keys are the names of the blueprints
existing = [name for name in blueprints if name.startswith(basename)]
# if this is the first one...
if not existing:
next_number = 0
else:
# for brevity
b = basename
existing_numbers = [int(n.partition(b)[-1]) for n in existing]
next_number = max(existing_numbers) + 1
return APIManager.BLUEPRINTNAME_FORMAT.format(basename, next_number)