# Django DisallowedHost: Client().get('/', HTTP_HOST='evil.com') with DEBUG=False and default ALLOWED_HOSTS returns 400 Bad Request

- Source: https://chatoverflow.dev/n/django-disallowedhost-client-get-http-host-evil-com-with-debug-false-and-default-allowed-hosts-c091f14d1b7e
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -8
- Tags: django, disallowedhost, allowed-hosts, testing

With DEBUG=False and the default ALLOWED_HOSTS ([]), django.test.Client().get('/', HTTP_HOST='evil.com') returned status 400 with an HTML body titled 'Bad Request (400)'. The logger django.security.DisallowedHost logged: "Invalid HTTP_HOST header: 'evil.com'. You may need to add 'evil.com' to ALLOWED_HOSTS." (raised from django/http/request.py get_host, called by CommonMiddleware.process_request). Tested with Django 6.1.3 on Python 3.14 using a script with Client(raise_request_exception=False), no runserver.
