本文整理匯總了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)