Decorator for Django REST Framework for validate params
Project description
django-params-validator
django restframe params validator
use for check django rest api params 用于检查django的rest接口的参数 包括参数的类型、范围 如果参数是bool类型,能将 1, 0转化为布尔值
pip install django-params-validator
Example
from django_params_validator import Params
@Params(book_num=int, book_num__gte=100, book_num__lte=200, book__optional=False)
def some_interface(request, *args, **kwargs):
pass
@Params(name=str, name__default='jack',
create_datetime=Params.DATETIME_STR, create_datetime__format='%Y-%m-%d',
colors=('red', 'blue', 'yellow'), colors__many=True)
def other_interface(request, *args, **kwargs):
colors = kwargs.get('colors')
# colors = ['']
pass
Options
TYPE
name=str
指定参数的类型
其中Params.DATETIME_STR是特殊的时间戳字符串格式
gt/lt/gte/lte
制定参数的范围
num__gte=100
optional
是否是可选参数
default
默认值
many
colors__many=True
是否是列表。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-params-validator-1.1.10.tar.gz
.
File metadata
- Download URL: django-params-validator-1.1.10.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45856d4355cb47ea7ad99dd43a4f5a29904e6fecb5a1d89945ccc052319afe88 |
|
MD5 | aa4935ea7e8cfc107fb94ef26070af6d |
|
BLAKE2b-256 | 48ddaf5bc6c1e7a4e93a664fde54dfb3e2a59768ea9f9a68ea1d5e2e96c60d0c |