shaare.it

DisallowedHost: Invalid HTTP_HOST header

7 Dec 2025

1 min read

DisallowedHost: Invalid HTTP_HOST header

$ curl -H "Host: example.test" http://localhost:8000/
DisallowedHost: Invalid HTTP_HOST header: 'example.test'. You may need to add 'example.test' to ALLOWED_HOSTS.

Why this happens

Django checks incoming Host header against ALLOWED_HOSTS. Unknown hosts are rejected.

Fix

Add hostnames or wildcard (not recommended) to ALLOWED_HOSTS.

Wrong code

ALLOWED_HOSTS = []

Fixed code

ALLOWED_HOSTS = ["localhost", "127.0.0.1", "example.test"]