@@ -18,44 +18,51 @@ Full documentation for the project is available at [https://nxexox.github.io/pyt
18
18
19
19
Install using ` pip ` , including any optional packages you want...
20
20
21
- pip install python-rest-framework
21
+ ``` bash
22
+ pip install python-rest-framework
23
+ ```
22
24
23
25
...or clone the project from github.
24
26
25
- git clone [email protected] :nxexox/python-rest-framework.git
26
-
27
+ ``` bash
28
+ git clone
[email protected] :nxexox/python-rest-framework.git
29
+ ```
27
30
28
31
## Example
29
32
30
33
For example, we will serialize the data from the request object.
31
34
32
35
First we write the serializer
33
36
34
- from rest_framework.serializers import (
35
- Serializer, CharField, IntegerField, ListField, FloatField
36
- )
37
+ ``` python
38
+ from rest_framework.serializers import (
39
+ Serializer, CharField, IntegerField, ListField, FloatField
40
+ )
37
41
38
- # Example serializer for parsing body data from web request.
39
- class ExampleSerializer(Serializer):
40
- char_field = CharField(label='This char field', required=True)
41
- int_field = IntegerField(label='This int field', required=True)
42
- list_float_field = ListField(child=FloatField(), required=True, min_length=2)
42
+ # Example serializer for parsing body data from web request.
43
+ class ExampleSerializer (Serializer ):
44
+ char_field = CharField(label = ' This char field' , required = True )
45
+ int_field = IntegerField(label = ' This int field' , required = True )
46
+ list_float_field = ListField(child = FloatField(), required = True , min_length = 2 )
47
+ ```
43
48
44
49
---
45
50
46
51
Now we process the request body with a serializer
47
52
48
- # web request data
49
- data = {
50
- 'char_field': 'example', 'int_field': 1,
51
- 'list_float_field': [1.0, 1.1, 1.2]
52
- }
53
-
54
- ser = ExampleSerializer(data=data)
55
- if ser.is_valid():
56
- print(ser.validated_data)
57
- else:
58
- print(ser.errors)
53
+ ``` python
54
+ # web request data
55
+ data = {
56
+ ' char_field' : ' example' , ' int_field' : 1 ,
57
+ ' list_float_field' : [1.0 , 1.1 , 1.2 ]
58
+ }
59
+
60
+ ser = ExampleSerializer(data = data)
61
+ if ser.is_valid():
62
+ print (ser.validated_data)
63
+ else :
64
+ print (ser.errors)
65
+ ```
59
66
60
67
[ docs ] : https://nxexox.github.io/python-rest-framework/
61
68
[ pypi-version ] : https://img.shields.io/pypi/v/python-rest-framework.svg
0 commit comments