Django REST framework 3.18

Last reviewed Sep 12, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. Python 3155 lines · 3.8K tokens
  2. Django 5.2157 lines · 4.1K tokens
  3. 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.depth on serializers whose relations reach users, credentials, tenants, or other sensitive models. DRF builds the generated nested serializers with fields = '__all__', so depth = 1 over a relation to User returns password, is_superuser, is_staff, and email even when the outer fields list is explicit; declare explicit nested serializers with allowlisted fields instead.
  • Mark ownership, tenant, role, price, status, audit, and server-generated fields read-only. Set read_only=True on explicitly declared fields because Meta.read_only_fields and extra_kwargs do not override them.
  • Validate cross-field invariants in validate and field invariants in the corresponding validator methods.
  • Do not rely on serializer field default values during partial=True updates 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