To resolve this error, you need to add the correct Host value to the ALLOWED_HOSTS setting. Here's how:
If you are using localhost as your host then you can change your file as below.
settings.py
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
Add the correct Host value to the list. For example, if your website's domain is mywebsite.com, you would add it like this:
ALLOWED_HOSTS = ['mywebsite.com']
If your website has multiple subdomains, you may also need to add those to the list. For example:
ALLOWED_HOSTS = ['mywebsite.com', 'www.mywebsite.com', 'subdomain.mywebsite.com']
Save the settings.py file and restart your Django development server. The invalid http_host header error should be resolved.
Note: Be sure to use the correct domain and subdomain names in the ALLOWED_HOSTS setting, as this is a critical security feature. If you're not sure what values to use, check with your web hosting provider or DNS administrator.
0 Comments