app.py 文件源码

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

项目:pymock 作者: halilkaya 项目源码 文件源码
def new_user():
    """
    Creates a new user
    """
    if not request.json:
        abort(400)
    username = request.json.get('username')
    password = request.json.get('password')
    name = request.json.get('name')
    email = request.json.get('email')
    if not username or not password or not name or not email:
        abort(400, 'Username, password, name or email is not given.')
    if User.query.filter_by(username=username).first() is not None:
        abort(400, 'Username is already in use.')
    user = User(username=username)
    user.hash_password(password)
    user.name = name
    user.email = email
    db.session.add(user)
    db.session.commit()
    return (jsonify({'username': user.username}), 201,
            {'Location': url_for('get_user', id=user.id, _external=True)})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号