创建客户端(注册)
api
v1
client.py
client.py
from app.libs.redprint import Redprint
api = Redprint("client")
@api.route("/register")
def create_client():
pass
枚举客户端类型
app
libs
enums.py
enums.py
from enum import Enum
class ClientTypeEnum(Enum):
USER_EMAIL = 100
USER_MOBILE = 101
# 微信小程序
USER_MINA = 200
# 微信公众号
USER_WX = 201
使用WTForms验证客户端传过来的参数
WTForms是一个支持多个web框架的form组件,主要用于对用户请求数据进行验证。
安装wtfroms:
pip install wtforms -i https://pypi.douban.com/simple
api
v1
validators
forms.py
forms.py
from wtforms import Form, StringField, IntegerField, validators
from app.libs.enums import ClientTypeEnum
class ClientForm(Form):
account = StringField(validators=[validators.data_required, validators.length(5, 32)])
secure = StringField()
type = IntegerField(validators=[validators.data_required])
def validate_type(self, value):
try:
client = ClientTypeEnum(value.data)
except ValueError as e:
raise e