Django REST framework 3.18
Last reviewed Sep 12, 2026
Prompt Details
Prompt Composition
3prompts
- Python 3155 lines · 3.8K tokens
- Django 5.2157 lines · 4.1K tokens
- Django REST framework 3.1861 lines · 2.2K tokens
Total373 lines · 10K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 79
- 89
- 95
- 117
- 201
- 203
- 208
- 209
- 214
- 250
- 287
- 295
- 306
- 307
- 319
- 328
- 338
- 347
- 352
- 367
- 379
- 384
- 409
- 416
- 426
- 427
- 434
- 470
- 502
- 521
- 524
- 532
- 601
- 611
- 613
- 614
- 639
- 640
- 674
- 732
- 770
- 772
- 776
- 778
- 798
- 807
- 829
- 862
- 915
- 916
- 918
- 942
- 1004
- 1021
- 1104
- 1275
- 1333
- 1336
- 1395
Prompt Preview
Apply the Python 3 and included Django 5.2 prompts first. DRF 3.18 also supports Django 6.0 and 6.1; on those releases keep the installed Django version and treat 5.2-specific version and patch statements in the baseline as not applicable. These rules cover Django REST framework 3.18 serializers, authentication, permissions, queryset isolation, parsers, throttling, and API deployment.
Serializers and writable fields
- Declare serializer fields explicitly for security-sensitive APIs instead of exposing every model field.
- Do not set
Meta.depthon serializers whose relations reach users, credentials, tenants, or other sensitive models. DRF builds the generated nested serializers withfields = '__all__', sodepth = 1over a relation toUserreturnspassword,is_superuser,is_staff, andemaileven when the outerfieldslist is explicit; declare explicit nested serializers with allowlistedfieldsinstead. - Mark ownership, tenant, role, price, status, audit, and server-generated fields read-only. Set
read_only=Trueon explicitly declared fields becauseMeta.read_only_fieldsandextra_kwargsdo not override them. - Validate cross-field invariants in
validateand field invariants in the corresponding validator methods. - Do not rely on serializer field
defaultvalues duringpartial=Trueupdates because DRF does not apply them; validate invariants against the supplied fields plus the authorized current instance, including privileged values that an omission would retain. - Override nested create and update behavior explicitly and prevent