當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。