本文整理汇总了Python中flask.current_app.view_functions方法的典型用法代码示例。如果您正苦于以下问题:Python current_app.view_functions方法的具体用法?Python current_app.view_functions怎么用?Python current_app.view_functions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.current_app
的用法示例。
在下文中一共展示了current_app.view_functions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_view_function
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def get_view_function(url, method='GET'):
adapter = current_app.url_map.bind('localhost')
try:
match = adapter.match(url, method=method)
except RequestRedirect as e:
# recursively match redirects
return get_view_function(e.new_url, method)
except (MethodNotAllowed, NotFound):
# no match
return None
try:
# return the view function and arguments
return current_app.view_functions[match[0]], match[1]
except KeyError:
# no view is associated with the endpoint
return None
示例2: routes
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def routes(): # pragma: no cover
"""Print available functions."""
if not current_app.debug:
abort(404)
func_list = []
for rule in current_app.url_map.iter_rules():
endpoint = rule.rule
methods = ", ".join(list(rule.methods))
doc = current_app.view_functions[rule.endpoint].__doc__
route = {
"endpoint": endpoint,
"methods": methods
}
if doc:
route["doc"] = doc
func_list.append(route)
func_list = sorted(func_list, key=lambda k: k['endpoint'])
return jsonify(func_list)
示例3: register_default
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def register_default(self, *metric_wrappers, **kwargs):
"""
Registers metric wrappers to track all endpoints,
similar to `export_defaults` but with user defined metrics.
Call this function after all routes have been set up.
Use the metric wrappers as arguments:
- metrics.counter(..)
- metrics.gauge(..)
- metrics.summary(..)
- metrics.histogram(..)
:param metric_wrappers: one or more metric wrappers to register
for all available endpoints
:param app: the Flask application to register the default metric for
(by default it is the application registered with this class)
"""
app = kwargs.get('app')
if app is None:
app = self.app or current_app
for endpoint, view_func in app.view_functions.items():
for wrapper in metric_wrappers:
view_func = wrapper(view_func)
app.view_functions[endpoint] = view_func
示例4: _get_executing_handler
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def _get_executing_handler():
return current_app.view_functions[request.endpoint]
示例5: method_is_explictly_overwritten
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def method_is_explictly_overwritten(self):
view_func = current_app.view_functions[request.endpoint]
return hasattr(view_func, '_explict_rule_set') and view_func._explict_rule_set is True
示例6: _get_rule_view
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def _get_rule_view(rule):
view_fn = current_app.view_functions[rule.endpoint]
view_module = inspect.getmodule(view_fn)
view_fn_name = view_fn.__name__
if 'View.as_view' in view_fn.__qualname__:
view_fn_name = view_fn.__dict__['view_class'].__name__
return f'{view_module.__name__}:{view_fn_name}'
示例7: generate
# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import view_functions [as 别名]
def generate(self, groups='all', sort=None):
"""Return a list of dict describing the routes specified by the
doc() method
Each dict contains:
- methods: the set of allowed methods (ie ['GET', 'POST'])
- rule: relative url (ie '/user/<int:id>')
- endpoint: function name (ie 'show_user')
- doc: docstring of the function
- args: function arguments
- defaults: defaults values for the arguments
By specifying the group or groups arguments, only routes belonging to
those groups will be returned.
Routes are sorted alphabetically based on the rule.
"""
groups_to_generate = list()
if type(groups) is list:
groups_to_generate = groups
elif type(groups) is str:
groups_to_generate.append(groups)
links = []
for rule in current_app.url_map.iter_rules():
if rule.endpoint == 'static':
continue
func = current_app.view_functions[rule.endpoint]
arguments = rule.arguments if rule.arguments else ['None']
func_groups = self.func_groups[func]
location = self.func_locations.get(func, None)
if func_groups.intersection(groups_to_generate):
links.append(
dict(
methods=rule.methods,
rule="%s" % rule,
endpoint=rule.endpoint,
docstring=func.__doc__,
args=arguments,
defaults=rule.defaults,
location=location,
)
)
if sort:
return sort(links)
else:
return sorted(links, key=itemgetter('rule'))