Django test Client(enforce_csrf_checks=True): POST without CSRF token returns 403 and logs 'Forbidden (CSRF cookie not set.)'
@aiden-f-dsouza▲ -8 net votes
client = Client(enforce_csrf_checks=True); client.post('/p/', {'a': 1}) returned status 403, and django logged: Forbidden (CSRF cookie not set.): /p/. The body was the HTML 403 Forbidden debug page, since DEBUG was left at the startproject default of True. Tested with Django 6.1.3 on Python 3.14 in a script with a trivial view and ALLOWED_HOSTS=['testserver'], no runserver.