python3使用flask編寫注冊post接口的方法
更新時(shí)間:2018年12月28日 09:38:37 作者:華賀
今天小編就為大家分享一篇python3使用flask編寫注冊post接口的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
使用python3的Flask庫寫了一個(gè)接口,封裝了很多東西,僅供參考即可!
代碼如下:
#!/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': '請求參數(shù)缺失!'}, 400
if not re.match(r'^1[3456789]\d{9}$', phone):
return {'msg': '手機(jī)號格式錯(cuò)誤!'}, 400
if mysql_utils.get_db_data(sqls_user.select_id_by_phone(), phone):
return {'msg': '該手機(jī)號已經(jīng)被注冊!'}, 500
mysql_utils.execute(sqls_user.register(), phone, aes_utils.encrypt(passwd)) # 執(zhí)行sql
return {'msg': '注冊成功!'}, 201
以上這篇python3使用flask編寫注冊post接口的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決python寫的windows服務(wù)不能啟動(dòng)的問題
使用py2exe生成windows服務(wù)在win7下可以正常運(yùn)行,但是到了xp下面可以安裝,但是無法啟動(dòng)2014-04-04
python安裝numpy&安裝matplotlib& scipy的教程
下面小編就為大家?guī)硪黄猵ython安裝numpy&安裝matplotlib& scipy的教程。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11
python神經(jīng)網(wǎng)絡(luò)InceptionV3模型復(fù)現(xiàn)詳解
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)InceptionV3模型復(fù)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>2022-05-05

