python rest框架。用于在python上轻松生成rest api的box实用程序
Python-Rest-Framework的Python项目详细描述
Python Rest Framework
python rest框架是一个成熟的rest api引擎。 您可以将所有精力集中在业务逻辑上,处理python rest框架的其余部分。
该项目的完整文档可在https://nxexox.github.io/python-rest-framework/获得。
要求
- Python(3.4、3.5、3.6、3.7)
- 六
安装
使用pip
安装,包括任何您想要的可选包…
pip install python-rest-framework
…或者从github克隆项目。
git clone git@github.com:nxexox/python-rest-framework.git
python web框架的版本
pip install python-rest-framework[flask]# For Flask framework pip install python-rest-framework[aiohttp]# For AioHttp framework pip install python-rest-framework[sanic]# For Sanic framework
示例
例如,我们将序列化来自请求对象的数据。
首先我们编写序列化程序
fromrest_framework.serializersimport(Serializer,CharField,IntegerField,ListField,FloatField)# Example serializer for parsing body data from web request.classExampleSerializer(Serializer):char_field=CharField(label='This char field',required=True)int_field=IntegerField(label='This int field',required=True)list_float_field=ListField(child=FloatField(),required=True,min_length=2)
现在,我们使用序列化程序处理请求正文
# web request datadata={'char_field':'example','int_field':1,'list_float_field':[1.0,1.1,1.2]}ser=ExampleSerializer(data=data)ifser.is_valid():print(ser.validated_data)else:print(ser.errors)