2019-09-02 10:37:26 3457浏览
本篇文章扣丁学堂Python培训小编给小伙伴们分享一篇python3使用flask编写注册post接口的方法的文章,文中有详细的代码列出供小伙伴们参考,感兴趣的小伙伴一起跟随小编过来看看吧。
	
 
	
 
	
 
使用python3的Flask库写了一个接口,封装了很多东西,仅供参考。
	
 
代码如下:
	
 
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
from flask import request
from flask_restful import Resource
import aes_utils
import mysql_utils
import sqls_user
class Register(Resource):
 """注册"""
 @staticmethod
 def post():
  data = request.get_json()
  phone = data.get('phone')
  passwd = data.get('passwd')
  if not all([phone, passwd]):
   return {'msg': '请求参数缺失!'}, 400
  if not re.match(r'^1[3456789]\d{9}$', phone):
   return {'msg': '手机号格式错误!'}, 400
  if mysql_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
	
最后想要了解更多关于Python和人工智能方面内容的小伙伴,请关注扣丁学堂Python培训官网、微信等平台,扣丁学堂IT职业在线学习教育平台为您提供权威的Python开发环境搭建视频,Python培训后的前景无限,行业薪资和未来的发展会越来越好的,扣丁学堂老师精心推出的Python视频教程定能让你快速掌握Python从入门到精通开发实战技能。扣丁学堂Python技术交流群:279521237。
	
 
	
                          
 
	
【关注微信公众号获取更多学习资料】 【扫码进入Python全栈开发免费公开课】