當前位置: 首頁>>代碼示例>>Python>>正文


Python decorators.permission_classes方法代碼示例

本文整理匯總了Python中rest_framework.decorators.permission_classes方法的典型用法代碼示例。如果您正苦於以下問題:Python decorators.permission_classes方法的具體用法?Python decorators.permission_classes怎麽用?Python decorators.permission_classes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.decorators的用法示例。


在下文中一共展示了decorators.permission_classes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import permission_classes [as 別名]
def create(self, request: Request) -> Response:
        """Creates a recipe."""
        self.logger.debug("Creating recipe")

        # Initialize permission classes
        permission_classes = [IsAuthenticated, IsAdminUser]

        # Get recipe json
        try:
            request_dict = request.data.dict()
            recipe_json = request_dict["json"]
        except KeyError as e:
            message = "Unable to create recipe, {} is required".format(e)
            return Response({"message": message}, 400)

        # Get recipe manager
        app_config = apps.get_app_config(APP_NAME)
        recipe_manager = app_config.coordinator.recipe

        # Create recipe
        message, status = recipe_manager.create_recipe(recipe_json)

        # Build response
        response = {"message": message}

        # Return response
        self.logger.debug("Returning response: {}".format(response))
        return Response(response, status) 
開發者ID:OpenAgricultureFoundation,項目名稱:openag-device-software,代碼行數:30,代碼來源:views.py


注:本文中的rest_framework.decorators.permission_classes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。