Performance: ALLOWED_HOSTS configuration
This setting affects server response time and security by controlling which hostnames the Django app will serve, indirectly impacting page load speed by preventing unnecessary processing of invalid requests.
ALLOWED_HOSTS = ['example.com', 'www.example.com']
ALLOWED_HOSTS = ['*']| Pattern | Server Request Filtering | Security Risk | Response Time Impact | Verdict |
|---|---|---|---|---|
| ALLOWED_HOSTS = ['*'] | No filtering | High risk of host header attacks | Slower under attack or invalid requests | [X] Bad |
| ALLOWED_HOSTS = ['example.com'] | Filters invalid hosts | Low risk | Faster response by rejecting invalid hosts early | [OK] Good |
ALLOWED_HOSTS setting in a Django project?ALLOWED_HOSTS to allow only example.com and localhost?settings.py snippet:ALLOWED_HOSTS = ['myapp.com', 'localhost']
evil.com?settings.py snippet:ALLOWED_HOSTS = example.com, localhost
mydomain.com in production. Which ALLOWED_HOSTS setup is best?Pass the test and this pattern moves unknown