-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.py
More file actions
28 lines (19 loc) · 715 Bytes
/
example.py
File metadata and controls
28 lines (19 loc) · 715 Bytes
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
from xdata import *
class UserSchema(Schema):
telephone = Str(length=11, required=True)
password = Str(min_length=8, max_length=16, required=True)
request_data = {
'telephone': '18180050000',
'password': 'idonotknow'
}
schema = UserSchema(request_data)
schema.validate()
if schema.valid:
print(schema.validated_data) # {'telephone': '18180050000', 'password': 'idonotknow'}
class UserSchema(Schema):
telephone = Str(length=11, required=True)
password = Str(min_length=8, max_length=16, required=True)
request_data = {}
schema = UserSchema(request_data)
if not schema.valid:
print(schema.errors) # {'telephone': 'telephone is required', 'password': 'password is required'}