msg.py 文件源码

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

项目:msg 作者: lily-mayfield 项目源码 文件源码
def post(self):
        """Create a new user.

        If a user already exists with the provided
        username, an HTTP 400 is sent.

        Returns:
            dict: If the user was successfully created,
                return a dictionary describing that
                created user.
            None: If aborted.

        """

        json_data = get_valid_json(self.SCHEMA_POST)
        bio = json_data.get('bio')
        username = json_data['username']
        password = json_data['password']
        new_user = models.User(username, password, bio=bio)
        db.session.add(new_user)

        try:
            db.session.commit()
        except sqlalchemy.exc.IntegrityError:
            message = "A user already exists with username: %s" % username
            flask_restful.abort(400, message=message)
        else:
            # will happen only if successful/no
            # error raised
            return new_user.to_dict()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号