Software⏱️ 2 min read📅 2026-06-03
How to Fix: How to fix Django error: DisallowedHost at / Invalid HTTP_HOST header: ... You may need to add ... to ALLOWED_HOSTS
Django DisallowedHost error fix
Quick Answer: To fix the Django DisallowedHost error, add your domain to ALLOWED_HOSTS in settings.py. Ensure you're using a valid domain and not just an IP address.
To resolve the DisallowedHost error in Django, you need to configure your project's ALLOWED_HOSTS setting.
🚀 How to Resolve This Issue
Method 1: Update ALLOWED_HOSTS in settings.py
- Step 1: Open your project's settings.py file and add the following line to the ALLOWED_HOSTS setting:
Example:
'ALLOWED_HOSTS': ['www.example.com', 'example.com'],Method 2: Use a reverse proxy server like Nginx or Apache
- Step 1: Configure your web server to forward requests from DigitalOcean's IP address to your Django project.
Example Configuration for Nginx:
'server {listen 80;
server {location / {
proxy_pass http://localhost:8000;}
}By following these steps, you should be able to resolve the DisallowedHost error in Django and access your website successfully.
❓ Frequently Asked Questions
Step 1: Open your project's settings.py file and add the following line to the ALLOWED_HOSTS setting:
'ALLOWED_HOSTS': ['www.example.com', 'example.com'],Method 2: Use a reverse proxy server like Nginx or ApacheStep 1: Configure your web server to forward requests from DigitalOcean's IP address to your Django project.
'server { listen 80; server { location / { proxy_pass http://localhost:8000; } }By following these steps, you should be able to resolve the DisallowedHost error in Django and access your website successfully.
🛠️ Related Fixes
How to Fix: Pc crashes shortly after launching game (rainbow
Fix Pc crashes shortly after launching game (rainbow six siege). Compl
How to Fix: Installing an APK on a locked down phone
Installing an APK on a locked down phone: Try using a rooted device, e
How to Fix: New PC build- no signal and no clue
Fix New PC build- no signal and no clue. Complete troubleshooting guid