python3使用flask编写注册post接口的方法
使用python3的Flask库写了一个接口,封装了很多东西,仅供参考即可!
代码如下:
#!/usr/bin/python3 #-*-coding:utf-8-*- importre fromflaskimportrequest fromflask_restfulimportResource importaes_utils importmysql_utils importsqls_user classRegister(Resource): """注册""" @staticmethod defpost(): data=request.get_json() phone=data.get('phone') passwd=data.get('passwd') ifnotall([phone,passwd]): return{'msg':'请求参数缺失!'},400 ifnotre.match(r'^1[3456789]\d{9}$',phone): return{'msg':'手机号格式错误!'},400 ifmysql_utils.get_db_data(sqls_user.select_id_by_phone(),phone): return{'msg':'该手机号已经被注册!'},500 mysql_utils.execute(sqls_user.register(),phone,aes_utils.encrypt(passwd))#执行sql return{'msg':'注册成功!'},201
以上这篇python3使用flask编写注册post接口的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。