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


Python views.MethodViewType方法代码示例

本文整理汇总了Python中flask.views.MethodViewType方法的典型用法代码示例。如果您正苦于以下问题:Python views.MethodViewType方法的具体用法?Python views.MethodViewType怎么用?Python views.MethodViewType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.views的用法示例。


在下文中一共展示了views.MethodViewType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: route

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import MethodViewType [as 别名]
def route(self, rule, *, parameters=None, **options):
        """Decorator to register url rule in application

        Also stores doc info for later registration

        Use this to decorate a :class:`MethodView <flask.views.MethodView>` or
        a resource function.

        :param str rule: URL rule as string.
        :param str endpoint: Endpoint for the registered URL rule (defaults
            to function name).
        :param list parameters: List of parameters relevant to all operations
            in this path, only used to document the resource.
        :param dict options: Options to be forwarded to the underlying
            :class:`werkzeug.routing.Rule <Rule>` object.
        """
        def decorator(func):

            # By default, endpoint name is function name
            endpoint = options.pop('endpoint', func.__name__)

            # Prevent registering several times the same endpoint
            # by silently renaming the endpoint in case of collision
            if endpoint in self._endpoints:
                endpoint = '{}_{}'.format(endpoint, len(self._endpoints))
            self._endpoints.append(endpoint)

            if isinstance(func, MethodViewType):
                view_func = func.as_view(endpoint)
            else:
                view_func = func

            # Add URL rule in Flask and store endpoint documentation
            self.add_url_rule(rule, endpoint, view_func, **options)
            self._store_endpoint_docs(endpoint, func, parameters, **options)

            return func

        return decorator 
开发者ID:marshmallow-code,项目名称:flask-smorest,代码行数:41,代码来源:blueprint.py

示例2: _store_endpoint_docs

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import MethodViewType [as 别名]
def _store_endpoint_docs(self, endpoint, obj, parameters, **options):
        """Store view or function doc info"""

        endpoint_doc_info = self._docs.setdefault(endpoint, OrderedDict())

        def store_method_docs(method, function):
            """Add auto and manual doc to table for later registration"""
            # Get documentation from decorators
            # Deepcopy doc info as it may be used for several methods and it
            # may be mutated in apispec
            doc = deepcopy(getattr(function, '_apidoc', {}))
            # Get summary/description from docstring
            doc['docstring'] = load_info_from_docstring(
                function.__doc__, delimiter=self.DOCSTRING_INFO_DELIMITER)
            # Store function doc infos for later processing/registration
            endpoint_doc_info[method.lower()] = doc

        # MethodView (class)
        if isinstance(obj, MethodViewType):
            for method in self.HTTP_METHODS:
                if method in obj.methods:
                    func = getattr(obj, method.lower())
                    store_method_docs(method, func)
        # Function
        else:
            methods = options.pop('methods', None) or ['GET']
            for method in methods:
                store_method_docs(method, obj)

        # Store parameters doc info from route decorator
        endpoint_doc_info['parameters'] = parameters 
开发者ID:marshmallow-code,项目名称:flask-smorest,代码行数:33,代码来源:blueprint.py

示例3: _get_endpoint

# 需要导入模块: from flask import views [as 别名]
# 或者: from flask.views import MethodViewType [as 别名]
def _get_endpoint(self, view_func, endpoint=None, plural=False):
        if endpoint:
            assert '.' not in endpoint, 'Api endpoints should not contain dots'
        elif isinstance(view_func, MethodViewType):
            endpoint = camel_to_snake_case(view_func.__name__)
            if hasattr(view_func, 'model') and plural:
                plural_model = camel_to_snake_case(view_func.model.__plural__)
                endpoint = f'{plural_model}_resource'
        else:
            endpoint = view_func.__name__
        return f'{self.name}.{endpoint}' 
开发者ID:briancappello,项目名称:flask-react-spa,代码行数:13,代码来源:extension.py


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