Skip to content

Commit 0f0d5ca

Browse files
committed
best-practices-of-django-rest-framework draft is added
1 parent c07d457 commit 0f0d5ca

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
layout: post
3+
title: "Best practices of Django Rest Framework"
4+
---
5+
6+
I've been developing APIs with [Django Rest Framework](https://www.django-rest-framework.org/) for 8 years. I would like to share my experiences in this blogpost.
7+
8+
## Do not use viewset
9+
10+
Viewsets are higher level abstractions of [Generic API Views](https://www.django-rest-framework.org/api-guide/generic-views/). It automtically creates
11+
12+
## Use drf-spectacular for auto generated documentation
13+
14+
## Have default Limit Offset pagination as default
15+
16+
### set maximum page size
17+
18+
## Have exception handler
19+
20+
## Enable filter backends
21+
22+
### django_filters.rest_framework.DjangoFilterBackend
23+
24+
### rest_framework.filters.OrderingFilter
25+
26+
## Have throttling
27+
28+
## Have default permission class
29+
30+
## Use HiddenInputField
31+
32+
## Do not write business logic in serializers
33+
34+
## Use multiple serializers if needed
35+
36+
## Validate in model
37+
38+
## Validate fields first then models
39+
40+
## Separate create and update serializers by functionalities
41+
42+
## Use ActionBasedSerializer if necessary
43+

0 commit comments

Comments
 (0)