base.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:zou 作者: cgwire 项目源码 文件源码
def post(self):
        """
        Create a model with data given in the request body. JSON format is
        expected. The model performs the validation automatically when
        instantiated.
        """

        try:
            data = request.json
            self.check_create_permissions(data)
            instance = self.model(**data)
            instance.save()
            return instance.serialize(), 201

        except TypeError as exception:
            current_app.logger.error(str(exception))
            return {"error": str(exception)}, 400

        except IntegrityError as exception:
            current_app.logger.error(str(exception))
            return {"error": str(exception)}, 400

        except StatementError as exception:
            current_app.logger.error(str(exception))
            return {"error": str(exception)}, 400

        except permissions.PermissionDenied:
            abort(403)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号