报错local variable 'usermobile' referenced before assignment

代码如下:
@api.route('/mobilereg', methods=['POST'])
def mobileCode():
    mobile = request.get_data("mobile")
    try:
        usermobile = User.query.filter_by(mobile=mobile).first()
    except Exception as e:
        current_app.logger.error(e)

    if usermobile:
        return {
            "errno": RET.DATAEXIST,
            "errmsg": "该手机号已被注册"
        }
return {
    "errno": RET.OK,
    "errmsg": "可以注册"
}

定义全局变量 usermobile
在代码中赋值前加入 global usermobile

你可能感兴趣的:(报错local variable 'usermobile' referenced before assignment)