架构:python+ flask +marshmallow+itsdangerous+pymysql
数据库:mysql
实现功能:登录、验证码、鉴权、用户、上传、下载、错误统一处理
api格式: restful + json
项目目录
web->controller ->uploads.py
import datetime
import os
import time
from flask import Blueprint, jsonify, request
from web import db
from web.setting import UPLOAD_URL
from web.token_auth import login_required
from web.model.uploads import Upload
# 创建蓝图
uploads = Blueprint('upload', __name__)
# 单文件上传
@uploads.route('/file', methods=["POST"])
@login_required()
def file():
if request.files.to_dict() == {}:
return jsonify(data={}, msg='file为空', code=500)
year_time = datetime.datetime.now().strftime('%Y')
month_time = datetime.datetime.now().strftime('%m')
day_time = datetime.datetime.now().strftime('%d')
pwd = UPLOAD_URL+'\\'+year_time+'\\'+month_time+'\\'+day_time
save_pwd = 'static\\uploads' + '\\' + year_time + '\\' + month_time + '\\' + day_time
word_name = os.path.exists(pwd)
f = request.files['file']
az = os.path.splitext(f.filename)[1]
if not word_name:
os.makedirs(pwd)
filename = int(round(time.time() * 1000))
upload_path = os.path.join(pwd, str(filename)+az)
save_upload_path = os.path.join(save_pwd, str(filename) + az)
f.save(upload_path)
data = Upload(name=str(filename)+az, path=save_upload_path)
db.session.add(data)
db.session.commit()
return jsonify(data={}, msg='上传成功', code=200)
# 多文件上传
@uploads.route('/files', methods=["POST"])
@login_required()
def files():
if len(request.files.getlist('files')) == 0:
return jsonify(data={}, msg='files为空', code=500)
year_time = datetime.datetime.now().strftime('%Y')
month_time = datetime.datetime.now().strftime('%m')
day_time = datetime.datetime.now().strftime('%d')
pwd = UPLOAD_URL + '\\' + year_time + '\\' + month_time + '\\' + day_time
save_pwd = 'static\\uploads' + '\\' + year_time + '\\' + month_time + '\\' + day_time
for f in request.files.getlist('files'):
az = os.path.splitext(f.filename)[1]
word_name = os.path.exists(pwd)
if not word_name:
os.makedirs(pwd)
filename = str(round(time.time() * 1000))
upload_path = os.path.join(pwd, filename+az)
save_upload_path = os.path.join(save_pwd, str(filename) + az)
f.save(upload_path)
data = Upload(name=str(filename) + az, path=save_upload_path)
db.session.add(data)
db.session.commit()
return jsonify(data={}, msg='上传成功', code=200)
web->controller ->user.py
import hashlib
from flask import jsonify, request, Blueprint, session
from marshmallow import ValidationError
from web.model.user import User
from web import db
from web.token_auth import create_token, login_required, verify_token
from web.validator.user import UserSchema, RegisterSchema, LoginSchema
from web.token_auth import check_token as check_token_auth
# 创建蓝图
user = Blueprint('user', __name__)
# 用户列表
@user.route('/index')
@login_required()
def index():
total_page = 1
if request.json is None:
items = User.query.all()
else:
page = request.json.get('page')
page_size = request.json.get('pageSize')
if page_size is None:
page_size = 10
if page is None:
items = User.query.all()
else:
data = User.query.paginate(page=page, per_page=page_size)
items = data.items
total_page = data.pages
datas = []
for user in items:
datas.append({'id': user.id, 'username': user.username, 'password': user.password, 'roleid': user.roleid})
return jsonify(data={'data': datas, 'total_page': total_page}, msg='成功', code=200)
# 添加用户
@user.route('/add', methods=["POST"])
@login_required()
def add():
# 校验字段
try:
result = UserSchema().load(request.json)
except ValidationError as e:
return jsonify(data=e.messages, msg='', code=500)
username = request.json.get('username')
password = request.json.get('password')
roleid = request.json.get('roleid')
# 判断用户名是否重复
filterData = User.query.filter(User.username == username).all()
if len(filterData) >= 1:
return jsonify(data={}, msg='用户名已存在', code=500)
data = User(username=username, password=hashlib.md5(password.encode()).hexdigest(), roleid=roleid)
db.session.add(data)
db.session.commit()
return jsonify(data={}, msg='成功', code=200)
# 修改用户
@user.route('/edit/<id>', methods=["PUT"])
@login_required()
def edit(id):
# 校验字段
try:
result = UserSchema().load(request.json)
except ValidationError as e:
return jsonify(data=e.messages, msg='', code=500)
username = request.json.get('username')
password = request.json.get('password')
roleid = request.json.get('roleid')
# 判断是否有此用户
filterData = User.query.filter(User.id == id).all()
if len(filterData) == 0:
return jsonify(data={}, msg='没有此用户', code=500)
oneData = User.query.filter(User.id == id).first()
oneData.username = username
oneData.password = hashlib.md5(password.encode()).hexdigest()
oneData.roleid = roleid
db.session.commit()
return jsonify(data={}, msg='成功', code=200)
# 删除用户
@user.route('/delete/<id>', methods=["DELETE"])
@login_required()
def delete(id):
# 判断是否有此用户
filterData = User.query.filter(User.id == id).all()
if len(filterData) == 0:
return jsonify(data={}, msg='没有此用户', code=500)
oneData = User.query.filter(User.id == id).first()
db.session.delete(oneData)
db.session.commit()
return jsonify(data={}, msg='成功', code=200)
# 注册
@user.route('/register', methods=["POST"])
def register():
try:
result = RegisterSchema().load(request.json)
except ValidationError as e:
return jsonify(data=e.messages, msg='', code=500)
username = request.json.get('username')
password = request.json.get('password')
# 判断用户名是否重复
filterData = User.query.filter(User.username == username).all()
if len(filterData) > 0:
return jsonify(data={}, msg='用户名重复', code=500)
data = User(username=username, password=hashlib.md5(password.encode()).hexdigest(), roleid=1)
db.session.add(data)
db.session.commit()
return jsonify(data={}, msg='成功', code=200)
# 登录
@user.route('/login', methods=["POST"])
def login():
try:
result = LoginSchema().load(request.json)
except ValidationError as e:
return jsonify(data=e.messages, msg='', code=500)
username = request.json.get('username')
password = request.json.get('password')
code = request.json.get('code').lower()
# 判断是否有此用户
filterData = User.query.filter(User.username == username).all()
if len(filterData) == 0:
return jsonify(data={}, msg='用户或密码错误', code=500)
if filterData[0].password != hashlib.md5(password.encode()).hexdigest():
return jsonify(data={}, msg='用户或密码错误', code=500)
if code != session.get(code):
return jsonify(data={}, msg='验证码错误', code=500)
# 生成token
token = str(create_token(username))[2:-1]
vkey = f"token_{username}"
session[vkey] = token
return jsonify(data={"username": filterData[0].username, "password": filterData[0].password, "token": token},
msg='成功', code=200)
# 退出
@user.route('/logout', methods=["POST"])
@login_required()
def logout():
try:
token = request.headers["Authorization"]
username = verify_token(token)
if username:
vkey = f"token_{username['user_code']}"
session.pop(vkey)
return jsonify(data={}, msg='退出成功', code=200)
else:
return jsonify(data={}, msg='退出失败', code=500)
except Exception as e:
return jsonify(data={}, msg='退出失败', code=500)
# 检查token
@user.route('/check_token', methods=["POST"])
@login_required()
def check_token():
if check_token_auth():
return jsonify(data=True, msg='', code=200)
else:
return jsonify(data=False, msg='', code=401)
web->controller->verificationCode.py
import base64
from flask import Blueprint, jsonify, session
from io import BytesIO
import random
import string
from PIL import Image, ImageFont, ImageDraw
# 创建蓝图
verificationCode = Blueprint('verification', __name__)
# 验证码
@verificationCode.route('/code')
def code():
code = imageCode().getImgCode()
return jsonify(data={'code': code}, msg='成功', code=200)
class imageCode():
# 验证码处理
def rndColor(self):
# 随机颜色
return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127))
def geneText(self):
# 生成4位验证码
return ''.join(random.sample(string.ascii_letters + string.digits, 4)) # ascii_letters是生成所有字母 digits是生成所有数字0-9
def drawLines(self, draw, num, width, height):
# 划线
for num in range(num):
x1 = random.randint(0, width / 2)
y1 = random.randint(0, height / 2)
x2 = random.randint(0, width)
y2 = random.randint(height / 2, height)
draw.line(((x1, y1), (x2, y2)), fill='black', width=1)
def getVerifyCode(self):
# 生成验证码图形
code = self.geneText()
# 图片大小120×50
width, height = 120, 50
# 新图片对象
im = Image.new('RGB', (width, height), 'white')
# 字体
font = ImageFont.truetype('../static/arial.ttf', 40)
# draw对象
draw = ImageDraw.Draw(im)
# 绘制字符串
for item in range(4):
draw.text((5 + random.randint(-3, 3) + 23 * item, 5 + random.randint(-3, 3)),
text=code[item], fill=self.rndColor(), font=font)
# 划线
self.drawLines(draw, 2, width, height)
return im, code
def getImgCode(self):
image, code = self.getVerifyCode()
# 图片以二进制形式写入
buf = BytesIO()
image.save(buf, 'jpeg')
buf_str = buf.getvalue()
# 将验证码字符串储存在session中
session[code.lower()] = code.lower()
return 'data:image/png;base64,'+str(base64.standard_b64encode(buf_str))[2:-1]
web->model->uploads.py
from web import db
class Upload(db.Model):
__tablename__ = 'upload'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(50))
path = db.Column(db.String(100))
def __init__(self, name, path):
self.name = name
self.path = path
def __repr__(self):
return '<Upload %r>' % self.name
web-model->user.py
from web import db
class User(db.Model):
__tablename__ = 'user'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(20))
password = db.Column(db.String(50))
roleid = db.Column(db.Integer)
def __init__(self, username, password, roleid):
self.username = username
self.password = password
self.roleid = roleid
def __repr__(self):
return '<User %r>' % self.username
web->static->uploads
web->static->arial.ttf
web->templates
web->validator->user.py
from marshmallow import Schema, fields, validate
class UserSchema(Schema):
username = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "用户名必填"})
password = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "密码名必填"})
roleid = fields.Integer(required=True, error_messages={"required": "角色id必填"})
class RegisterSchema(Schema):
username = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "用户名必填"})
password = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "密码名必填"})
class LoginSchema(Schema):
username = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "用户名必填"})
password = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "密码名必填"})
code = fields.String(required=True, validate=validate.Length(min=1), error_messages={"required": "验证码必填"})
web->__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
app.config.from_object('web.setting')
app.secret_key = '\xca\x0c\x86\x04\x98@\x02b\x1b7\x8c\x88]\x1b\xd7"+\xe6px@\xc3#\\'
db = SQLAlchemy(app, use_native_unicode='utf8')
web->setting.py
import os
basepath = os.path.dirname(__file__)
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@localhost:3306/test'
# 'mysql+pymysql://用户名称:密码@localhost:端口/数据库名称'
SQLALCHEMY_TRACK_MODIFICATIONS = True
SECRET_KEY = '123456789abcd'
EXCEPTION = 36000
UPLOAD_URL = os.path.join(basepath, 'static\\uploads')
web->token_auth.py
import functools
from flask import request, jsonify, session
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, SignatureExpired, BadSignature
from web.setting import SECRET_KEY, EXCEPTION
# 生成token, 有效时间为600min
def create_token(user_name, expiration=EXCEPTION):
# 第一个参数是内部私钥
# 第二个参数是有效期(秒)
s = Serializer(SECRET_KEY, expires_in=expiration)
return s.dumps({'user_code': user_name})
# 解析token
def verify_token(token):
s = Serializer(SECRET_KEY)
# token正确
try:
data = s.loads(token)
return data
# token过期
except SignatureExpired:
return None
# token错误
except BadSignature:
return None
# 校验token
def check_token():
token = request.headers["Authorization"]
username = verify_token(token)
if username:
vkey = f"token_{username['user_code']}"
if session.get(vkey) is None:
return False
else:
if session.get(vkey) == token:
return True
else:
return False
# 校验装饰器
def login_required():
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kw):
try:
# 在请求头上拿到token
token = request.headers["Authorization"]
if not check_token():
return jsonify(data={}, msg='登录已过期', code=401)
except Exception as e:
# 没接收的到token,给前端抛出错误
return jsonify(data={}, msg='缺失token', code=500)
s = Serializer(SECRET_KEY)
try:
user = s.loads(token)
except Exception as e:
return jsonify(data={}, msg='登录已过期', code=401)
return func(*args, **kw)
return wrapper
return decorator
Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
flask = "*"
myapplication = "*"
marshmallow = "*"
pillow = "*"
[dev-packages]
[requires]
python_version = "3.8"
Pipfile.lock
{
"_meta": {
"hash": {
"sha256": "1a898e86ceaace252ad2e7f89b4818c9fe5ba390dfa6b50eefe8db7bb383ae9a"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.8"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"click": {
"hashes": [
"sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3",
"sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"
],
"markers": "python_version >= '3.6'",
"version": "==8.0.3"
},
"colorama": {
"hashes": [
"sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b",
"sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"
],
"markers": "platform_system == 'Windows'",
"version": "==0.4.4"
},
"flask": {
"hashes": [
"sha256:7b2fb8e934ddd50731893bdcdb00fc8c0315916f9fcd50d22c7cc1a95ab634e2",
"sha256:cb90f62f1d8e4dc4621f52106613488b5ba826b2e1e10a33eac92f723093ab6a"
],
"index": "pypi",
"version": "==2.0.2"
},
"itsdangerous": {
"hashes": [
"sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c",
"sha256:9e724d68fc22902a1435351f84c3fb8623f303fffcc566a4cb952df8c572cff0"
],
"markers": "python_version >= '3.6'",
"version": "==2.0.1"
},
"jinja2": {
"hashes": [
"sha256:077ce6014f7b40d03b47d1f1ca4b0fc8328a692bd284016f806ed0eaca390ad8",
"sha256:611bb273cd68f3b993fabdc4064fc858c5b47a973cb5aa7999ec1ba405c87cd7"
],
"markers": "python_version >= '3.6'",
"version": "==3.0.3"
},
"markupsafe": {
"hashes": [
"sha256:01a9b8ea66f1658938f65b93a85ebe8bc016e6769611be228d797c9d998dd298",
"sha256:023cb26ec21ece8dc3907c0e8320058b2e0cb3c55cf9564da612bc325bed5e64",
"sha256:0446679737af14f45767963a1a9ef7620189912317d095f2d9ffa183a4d25d2b",
"sha256:04635854b943835a6ea959e948d19dcd311762c5c0c6e1f0e16ee57022669194",
"sha256:0717a7390a68be14b8c793ba258e075c6f4ca819f15edfc2a3a027c823718567",
"sha256:0955295dd5eec6cb6cc2fe1698f4c6d84af2e92de33fbcac4111913cd100a6ff",
"sha256:0d4b31cc67ab36e3392bbf3862cfbadac3db12bdd8b02a2731f509ed5b829724",
"sha256:10f82115e21dc0dfec9ab5c0223652f7197feb168c940f3ef61563fc2d6beb74",
"sha256:168cd0a3642de83558a5153c8bd34f175a9a6e7f6dc6384b9655d2697312a646",
"sha256:1d609f577dc6e1aa17d746f8bd3c31aa4d258f4070d61b2aa5c4166c1539de35",
"sha256:1f2ade76b9903f39aa442b4aadd2177decb66525062db244b35d71d0ee8599b6",
"sha256:20dca64a3ef2d6e4d5d615a3fd418ad3bde77a47ec8a23d984a12b5b4c74491a",
"sha256:2a7d351cbd8cfeb19ca00de495e224dea7e7d919659c2841bbb7f420ad03e2d6",
"sha256:2d7d807855b419fc2ed3e631034685db6079889a1f01d5d9dac950f764da3dad",
"sha256:2ef54abee730b502252bcdf31b10dacb0a416229b72c18b19e24a4509f273d26",
"sha256:36bc903cbb393720fad60fc28c10de6acf10dc6cc883f3e24ee4012371399a38",
"sha256:37205cac2a79194e3750b0af2a5720d95f786a55ce7df90c3af697bfa100eaac",
"sha256:3c112550557578c26af18a1ccc9e090bfe03832ae994343cfdacd287db6a6ae7",
"sha256:3dd007d54ee88b46be476e293f48c85048603f5f516008bee124ddd891398ed6",
"sha256:4296f2b1ce8c86a6aea78613c34bb1a672ea0e3de9c6ba08a960efe0b0a09047",
"sha256:47ab1e7b91c098ab893b828deafa1203de86d0bc6ab587b160f78fe6c4011f75",
"sha256:49e3ceeabbfb9d66c3aef5af3a60cc43b85c33df25ce03d0031a608b0a8b2e3f",
"sha256:4dc8f9fb58f7364b63fd9f85013b780ef83c11857ae79f2feda41e270468dd9b",
"sha256:4efca8f86c54b22348a5467704e3fec767b2db12fc39c6d963168ab1d3fc9135",
"sha256:53edb4da6925ad13c07b6d26c2a852bd81e364f95301c66e930ab2aef5b5ddd8",
"sha256:5855f8438a7d1d458206a2466bf82b0f104a3724bf96a1c781ab731e4201731a",
"sha256:594c67807fb16238b30c44bdf74f36c02cdf22d1c8cda91ef8a0ed8dabf5620a",
"sha256:5b6d930f030f8ed98e3e6c98ffa0652bdb82601e7a016ec2ab5d7ff23baa78d1",
"sha256:5bb28c636d87e840583ee3adeb78172efc47c8b26127267f54a9c0ec251d41a9",
"sha256:60bf42e36abfaf9aff1f50f52644b336d4f0a3fd6d8a60ca0d054ac9f713a864",
"sha256:611d1ad9a4288cf3e3c16014564df047fe08410e628f89805e475368bd304914",
"sha256:6300b8454aa6930a24b9618fbb54b5a68135092bc666f7b06901f897fa5c2fee",
"sha256:63f3268ba69ace99cab4e3e3b5840b03340efed0948ab8f78d2fd87ee5442a4f",
"sha256:6557b31b5e2c9ddf0de32a691f2312a32f77cd7681d8af66c2692efdbef84c18",
"sha256:693ce3f9e70a6cf7d2fb9e6c9d8b204b6b39897a2c4a1aa65728d5ac97dcc1d8",
"sha256:6a7fae0dd14cf60ad5ff42baa2e95727c3d81ded453457771d02b7d2b3f9c0c2",
"sha256:6c4ca60fa24e85fe25b912b01e62cb969d69a23a5d5867682dd3e80b5b02581d",
"sha256:6fcf051089389abe060c9cd7caa212c707e58153afa2c649f00346ce6d260f1b",
"sha256:7d91275b0245b1da4d4cfa07e0faedd5b0812efc15b702576d103293e252af1b",
"sha256:89c687013cb1cd489a0f0ac24febe8c7a666e6e221b783e53ac50ebf68e45d86",
"sha256:8d206346619592c6200148b01a2142798c989edcb9c896f9ac9722a99d4e77e6",
"sha256:905fec760bd2fa1388bb5b489ee8ee5f7291d692638ea5f67982d968366bef9f",
"sha256:97383d78eb34da7e1fa37dd273c20ad4320929af65d156e35a5e2d89566d9dfb",
"sha256:984d76483eb32f1bcb536dc27e4ad56bba4baa70be32fa87152832cdd9db0833",
"sha256:99df47edb6bda1249d3e80fdabb1dab8c08ef3975f69aed437cb69d0a5de1e28",
"sha256:9f02365d4e99430a12647f09b6cc8bab61a6564363f313126f775eb4f6ef798e",
"sha256:a30e67a65b53ea0a5e62fe23682cfe22712e01f453b95233b25502f7c61cb415",
"sha256:ab3ef638ace319fa26553db0624c4699e31a28bb2a835c5faca8f8acf6a5a902",
"sha256:aca6377c0cb8a8253e493c6b451565ac77e98c2951c45f913e0b52facdcff83f",
"sha256:add36cb2dbb8b736611303cd3bfcee00afd96471b09cda130da3581cbdc56a6d",
"sha256:b2f4bf27480f5e5e8ce285a8c8fd176c0b03e93dcc6646477d4630e83440c6a9",
"sha256:b7f2d075102dc8c794cbde1947378051c4e5180d52d276987b8d28a3bd58c17d",
"sha256:baa1a4e8f868845af802979fcdbf0bb11f94f1cb7ced4c4b8a351bb60d108145",
"sha256:be98f628055368795d818ebf93da628541e10b75b41c559fdf36d104c5787066",
"sha256:bf5d821ffabf0ef3533c39c518f3357b171a1651c1ff6827325e4489b0e46c3c",
"sha256:c47adbc92fc1bb2b3274c4b3a43ae0e4573d9fbff4f54cd484555edbf030baf1",
"sha256:cdfba22ea2f0029c9261a4bd07e830a8da012291fbe44dc794e488b6c9bb353a",
"sha256:d6c7ebd4e944c85e2c3421e612a7057a2f48d478d79e61800d81468a8d842207",
"sha256:d7f9850398e85aba693bb640262d3611788b1f29a79f0c93c565694658f4071f",
"sha256:d8446c54dc28c01e5a2dbac5a25f071f6653e6e40f3a8818e8b45d790fe6ef53",
"sha256:deb993cacb280823246a026e3b2d81c493c53de6acfd5e6bfe31ab3402bb37dd",
"sha256:e0f138900af21926a02425cf736db95be9f4af72ba1bb21453432a07f6082134",
"sha256:e9936f0b261d4df76ad22f8fee3ae83b60d7c3e871292cd42f40b81b70afae85",
"sha256:f0567c4dc99f264f49fe27da5f735f414c4e7e7dd850cfd8e69f0862d7c74ea9",
"sha256:f5653a225f31e113b152e56f154ccbe59eeb1c7487b39b9d9f9cdb58e6c79dc5",
"sha256:f826e31d18b516f653fe296d967d700fddad5901ae07c622bb3705955e1faa94",
"sha256:f8ba0e8349a38d3001fae7eadded3f6606f0da5d748ee53cc1dab1d6527b9509",
"sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51",
"sha256:fa130dd50c57d53368c9d59395cb5526eda596d3ffe36666cd81a44d56e48872"
],
"markers": "python_version >= '3.6'",
"version": "==2.0.1"
},
"marshmallow": {
"hashes": [
"sha256:04438610bc6dadbdddb22a4a55bcc7f6f8099e69580b2e67f5a681933a1f4400",
"sha256:4c05c1684e0e97fe779c62b91878f173b937fe097b356cd82f793464f5bc6138"
],
"index": "pypi",
"version": "==3.14.1"
},
"myapplication": {
"hashes": [
"sha256:ca19555afe8c67247043f912d8b8b1a227e617988aa1ca83baaac8269830e428"
],
"index": "pypi",
"version": "==0.1.0"
},
"pillow": {
"hashes": [
"sha256:066f3999cb3b070a95c3652712cffa1a748cd02d60ad7b4e485c3748a04d9d76",
"sha256:0a0956fdc5defc34462bb1c765ee88d933239f9a94bc37d132004775241a7585",
"sha256:0b052a619a8bfcf26bd8b3f48f45283f9e977890263e4571f2393ed8898d331b",
"sha256:1394a6ad5abc838c5cd8a92c5a07535648cdf6d09e8e2d6df916dfa9ea86ead8",
"sha256:1bc723b434fbc4ab50bb68e11e93ce5fb69866ad621e3c2c9bdb0cd70e345f55",
"sha256:244cf3b97802c34c41905d22810846802a3329ddcb93ccc432870243211c79fc",
"sha256:25a49dc2e2f74e65efaa32b153527fc5ac98508d502fa46e74fa4fd678ed6645",
"sha256:2e4440b8f00f504ee4b53fe30f4e381aae30b0568193be305256b1462216feff",
"sha256:3862b7256046fcd950618ed22d1d60b842e3a40a48236a5498746f21189afbbc",
"sha256:3eb1ce5f65908556c2d8685a8f0a6e989d887ec4057326f6c22b24e8a172c66b",
"sha256:3f97cfb1e5a392d75dd8b9fd274d205404729923840ca94ca45a0af57e13dbe6",
"sha256:493cb4e415f44cd601fcec11c99836f707bb714ab03f5ed46ac25713baf0ff20",
"sha256:4acc0985ddf39d1bc969a9220b51d94ed51695d455c228d8ac29fcdb25810e6e",
"sha256:5503c86916d27c2e101b7f71c2ae2cddba01a2cf55b8395b0255fd33fa4d1f1a",
"sha256:5b7bb9de00197fb4261825c15551adf7605cf14a80badf1761d61e59da347779",
"sha256:5e9ac5f66616b87d4da618a20ab0a38324dbe88d8a39b55be8964eb520021e02",
"sha256:620582db2a85b2df5f8a82ddeb52116560d7e5e6b055095f04ad828d1b0baa39",
"sha256:62cc1afda735a8d109007164714e73771b499768b9bb5afcbbee9d0ff374b43f",
"sha256:70ad9e5c6cb9b8487280a02c0ad8a51581dcbbe8484ce058477692a27c151c0a",
"sha256:72b9e656e340447f827885b8d7a15fc8c4e68d410dc2297ef6787eec0f0ea409",
"sha256:72cbcfd54df6caf85cc35264c77ede902452d6df41166010262374155947460c",
"sha256:792e5c12376594bfcb986ebf3855aa4b7c225754e9a9521298e460e92fb4a488",
"sha256:7b7017b61bbcdd7f6363aeceb881e23c46583739cb69a3ab39cb384f6ec82e5b",
"sha256:81f8d5c81e483a9442d72d182e1fb6dcb9723f289a57e8030811bac9ea3fef8d",
"sha256:82aafa8d5eb68c8463b6e9baeb4f19043bb31fefc03eb7b216b51e6a9981ae09",
"sha256:84c471a734240653a0ec91dec0996696eea227eafe72a33bd06c92697728046b",
"sha256:8c803ac3c28bbc53763e6825746f05cc407b20e4a69d0122e526a582e3b5e153",
"sha256:93ce9e955cc95959df98505e4608ad98281fff037350d8c2671c9aa86bcf10a9",
"sha256:9a3e5ddc44c14042f0844b8cf7d2cd455f6cc80fd7f5eefbe657292cf601d9ad",
"sha256:a4901622493f88b1a29bd30ec1a2f683782e57c3c16a2dbc7f2595ba01f639df",
"sha256:a5a4532a12314149d8b4e4ad8ff09dde7427731fcfa5917ff16d0291f13609df",
"sha256:b8831cb7332eda5dc89b21a7bce7ef6ad305548820595033a4b03cf3091235ed",
"sha256:b8e2f83c56e141920c39464b852de3719dfbfb6e3c99a2d8da0edf4fb33176ed",
"sha256:c70e94281588ef053ae8998039610dbd71bc509e4acbc77ab59d7d2937b10698",
"sha256:c8a17b5d948f4ceeceb66384727dde11b240736fddeda54ca740b9b8b1556b29",
"sha256:d82cdb63100ef5eedb8391732375e6d05993b765f72cb34311fab92103314649",
"sha256:d89363f02658e253dbd171f7c3716a5d340a24ee82d38aab9183f7fdf0cdca49",
"sha256:d99ec152570e4196772e7a8e4ba5320d2d27bf22fdf11743dd882936ed64305b",
"sha256:ddc4d832a0f0b4c52fff973a0d44b6c99839a9d016fe4e6a1cb8f3eea96479c2",
"sha256:e3dacecfbeec9a33e932f00c6cd7996e62f53ad46fbe677577394aaa90ee419a",
"sha256:eb9fc393f3c61f9054e1ed26e6fe912c7321af2f41ff49d3f83d05bacf22cc78"
],
"index": "pypi",
"version": "==8.4.0"
},
"werkzeug": {
"hashes": [
"sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f",
"sha256:aa2bb6fc8dee8d6c504c0ac1e7f5f7dc5810a9903e793b6f715a9f015bdadb9a"
],
"markers": "python_version >= '3.6'",
"version": "==2.0.2"
}
},
"develop": {}
}
README.md
# 运行
cd 项目
python ./runserver.py
requirements.txt
itsdangerous~=2.0.1
marshmallow~=3.14.1
flask~=2.0.2
Pillow~=8.4.0
runserver.py
from flask import jsonify
from web import app
from web.controller.uploads import uploads
from web.controller.user import user
from web.controller.verificationCode import verificationCode
@app.route('/')
def hello_word():
return 'Hello World!'
@app.errorhandler(404)
def page_404(error):
return jsonify(data={}, msg='', code=404)
@app.errorhandler(500)
def page_500(error):
return jsonify(data={}, msg='', code=500)
app.register_blueprint(user, url_prefix='/user')
app.register_blueprint(verificationCode, url_prefix='/verification')
app.register_blueprint(uploads, url_prefix='/uploads')
if __name__ == '__main__':
app.run(debug=True)
test.sql
|