Django 5.2
Last reviewed Oct 11, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Django 5.2157 lines · 4.1K tokens
Total312 lines · 7.9K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 79
- 89
- 95
- 117
- 201
- 203
- 208
- 209
- 214
- 250
- 287
- 295
- 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 baseline first, then these rules for Django 5.2. Use the latest supported 5.2.x patch on a maintained, compatible Python release. Preserve Django's protections; document and test any necessary exception.
Security baseline
- Prefer Django's forms, ORM, templates, authentication, session, CSRF, signing, and security middleware over custom security code.
- Set security controls in production settings without permissive fallbacks; run
manage.py check --deployagainst those settings and resolve its security warnings. - Keep
DEBUG = Falseand use a production WSGI or ASGI server, nevermanage.py runserver.
Authentication
- Verify credentials with
django.contrib.auth.authenticate(); rejectNoneand pass only an authenticated user tologin(). - Establish and end sessions with Django's
login()andlogout(), not manual session-key edits. - After saving a custom password change, call
update_session_auth_hash()to retain the current login and rotate its key. - Protect function views with
@login_required, class views with leftmostLoginRequiredMixin. - For deny-by-default sites, place
LoginRequiredMiddlewareafterAuthenticationMiddleware; use@login_not_requiredfor intended public views, including login and recovery, to avoid redirect loops. - Retain
ModelBackendinactive-user rejection; enforceis_activein every custom backend. - Return
Nonefor invalid credentials; raisePermissionDeniedonly to stop later backends. - Add application/proxy/server rate limiting for login, password-reset, and other credential