脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python3使用flask编写注册post接口的方法

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

2021-05-09 00:14华贺 Python

今天小编就为大家分享一篇python3使用flask编写注册post接口的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

使用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

延伸 · 阅读

精彩推荐