本文整理汇总了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)