python3使用flask编写注册post接口的方法

时间:2022-09-11 20:00:25

使用python3的Flask库写了一个接口,封装了很多东西,仅供参考即可!

代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/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

以上这篇python3使用flask编写注册post接口的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/HH775313602/article/details/81093404