当前位置: 首页>>代码示例>>Python>>正文


Python current_app.view_functions方法代码示例

本文整理汇总了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 
开发者ID:honmaple,项目名称:maple-blog,代码行数:19,代码来源:alias.py

示例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) 
开发者ID:fastlane-queue,项目名称:fastlane,代码行数:23,代码来源:routes.py

示例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 
开发者ID:rycus86,项目名称:prometheus_flask_exporter,代码行数:28,代码来源:__init__.py

示例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] 
开发者ID:justanr,项目名称:flask-allows,代码行数:4,代码来源:views.py

示例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 
开发者ID:bouncer-app,项目名称:flask-bouncer,代码行数:5,代码来源:flask_bouncer.py

示例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}' 
开发者ID:briancappello,项目名称:flask-react-spa,代码行数:9,代码来源:urls.py

示例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')) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:52,代码来源:autodoc.py


注:本文中的flask.current_app.view_functions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。