Forums

DisallowedHost at /

Invalid HTTP_HOST header: 'xxxxxx'. You may need to add u'xxxxxx' to ALLOWED_HOSTS.

getting this error even if Debug = False and allowed host is set to my domain name.

Setting DEBUG to false no longer allows access via hostnames that aren't in ALLOWED_HOSTS in the most recent versions of Django -- it turned out to be a security flaw.

You say you set it to your domain name -- it needs be an element in a list or a tuple. For example:

ALLOWED_HOSTS =  ["privacyismyth.pythonanywhere.com"]

ALLOWED_HOSTS = ["jeon.pythonanywhere.com"]

Yes, exactly -- if you put that in your settings file then you'll get rid of this error.

Please, don't forget to "Reload" your app at the "Web" tab of your control panel.

Yup, that's a very good point.

how set my webpage in aloowed hosts?

if this is a django webapp, you can set that in your settings.py file

Thanks Esavitskiy, reloading the app worked!

I made it work by changing the local_settings.py file instead of the settings file.

[edited by admin: formmatting]

DisallowedHost at /
Invalid HTTP_HOST header: 'subrahmanyam0326.pythonanywhere.com'. You may need to add 'subrahmanyam0326.pythonanywhere.com' to ALLOWED_HOSTS.
Request Method: GET
Request URL:    http://subrahmanyam0326.pythonanywhere.com/
Django Version: 3.0
Exception Type: DisallowedHost
Exception Value:    
Invalid HTTP_HOST header: 'subrahmanyam0326.pythonanywhere.com'. You may need to add 'subrahmanyam0326.pythonanywhere.com' to ALLOWED_HOSTS.
Exception Location: /home/subrahmanyam0326/.virtualenvs/djangofolder/lib/python3.6/site-packages/django/http/request.py in get_host, line 122
Python Executable:  /usr/local/bin/uwsgi
Python Version: 3.6.9
Python Path:    
['/var/www',
 '.',
 '',
 '/var/www',
 '/home/subrahmanyam0326/.virtualenvs/djangofolder/lib/python36.zip',
 '/home/subrahmanyam0326/.virtualenvs/djangofolder/lib/python3.6',
 '/home/subrahmanyam0326/.virtualenvs/djangofolder/lib/python3.6/lib-dynload',
 '/usr/lib/python3.6',
 '/home/subrahmanyam0326/.virtualenvs/djangofolder/lib/python3.6/site-packages',
 '/home/subrahmanyam0326/first_repository/crudexample/']
Server time:    Thu, 17 Dec 2020 11:04:23 +0000

Hi, you should probably "add 'subrahmanyam0326.pythonanywhere.com' to ALLOWED_HOSTS" as the error message says. It's in the settings.py file.

Environment:

Request Method: GET
Request URL: https://swati1.pythonanywhere.com/

Django Version: 3.2.12
Python Version: 3.6.13
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'pages.apps.PagesConfig',
 'quotes.apps.QuotesConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/home/swati1/.virtualenvs/env_mfdw/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/swati1/.virtualenvs/env_mfdw/lib/python3.6/site-packages/django/utils/deprecation.py", line 116, in __call__
    response = self.process_request(request)
  File "/home/swati1/.virtualenvs/env_mfdw/lib/python3.6/site-packages/django/middleware/common.py", line 48, in process_request
    host = request.get_host()
  File "/home/swati1/.virtualenvs/env_mfdw/lib/python3.6/site-packages/django/http/request.py", line 149, in get_host
    raise DisallowedHost(msg)

Exception Type: DisallowedHost at /
Exception Value: Invalid HTTP_HOST header: 'swati1.pythonanywhere.com'. You may need to add 'swati1.pythonanywhere.com' to ALLOWED_HOSTS.

You may need to add 'swati1.pythonanywhere.com' to ALLOWED_HOSTS.

In case anyone else is having the same issue that I was having. I am new to coding and there is a lot I don't know yet. I kept getting the disallowed host. After I made the changes to the settings.py file and then did the push to Github I was not doing the git pull on the bash console. Once I did the git pull I quit getting this error. Hope this helps!