[go: up one dir, main page]

0% found this document useful (0 votes)
80 views5 pages

Django DRF

1. DRF's request.data attribute allows handling of JSON data and PUT/PATCH requests, unlike Django's request.POST which only supports form-encoded POST data. 2. The Serializer is_valid() method first checks that initial data is available but validated data is not, then runs validation methods like run_validation(). 3. The run_validation() method checks that initial data is not empty, then runs field-level validation via to_internal_value(), applies defaults via run_validator(), and object-level validation via the serializer's validate() method.

Uploaded by

shashank gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views5 pages

Django DRF

1. DRF's request.data attribute allows handling of JSON data and PUT/PATCH requests, unlike Django's request.POST which only supports form-encoded POST data. 2. The Serializer is_valid() method first checks that initial data is available but validated data is not, then runs validation methods like run_validation(). 3. The run_validation() method checks that initial data is not empty, then runs field-level validation via to_internal_value(), applies defaults via run_validator(), and object-level validation via the serializer's validate() method.

Uploaded by

shashank gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Request

1. Django's request.POST only gives you support for POST requests with form encoded data. If
you want to handle JSON, or if you want to make PUT and PATCH requests, then REST
framework's request.data is what you want, yes.

DRF:
Serilizer
1. is_valid() method:
a. This method is written in base serializer

b.
c. This method first check that initial data must be available but validated data should
not be available.
d. After checking this it goes for run_validation method over the available initial data.

2. run_validation () method
a. it is implemented in the serializer class.
b.
c. This method first checks that initial data must not be empty.
d. It in all goes through three methods
e. { ‘ to_internal_value ‘ : “ it checks all field level validation,
f. ‘ run_validator ‘ : “it checks for all defaults,
g. ‘ validator ‘: “it checks for all validation function made for object level validation”
h. }
i. Then it runs the to_internal_value method which is also implemented in the serializer
class.
j.
k.
l. In this method we go field by field.
m. For each field we check for validate_method which is explained at the link below
n. https://www.django-rest-framework.org/api-guide/serializers/#field-level-validation
o.
p. After checking for all field level validate method we apply run_validator which applies
all default value to the field.
q. And finally we pass all these value through .validate() method which we can define in
the serializer class (object level validation)

r.
s. Other object level validations are shown below:
t.
u.

You might also like