Forums

DisallowedHost at /: Invalid HTTP_HOST header

Hello,

I'm following this tutorial (https://tutorial.djangogirls.org/en/deploy/) and I keep getting a DisallowedHost error. (Screenshot: https://ibb.co/c1beYG)

In settings.py, added 'chocoberrie.pythonanywhere.com' to the ALLOWED_HOSTS list, and I made sure to include it in quotation marks and keep the brackets. I even added it to requests.py, at line 113 (indicated in the error message).

Screenshots: https://ibb.co/jwUNnb and https://ibb.co/fbmrfw

I also committed the changes to Git, and I double-checked the repository to make sure that the URL was added to ALLOWED_HOSTS. (It was.) And of course, I reuploaded the changes on PythonAnywhere too.

After all that, I'm still getting the error! It's really frustrating, and I don't know what else to do. Any help would be much appreciated!

can you open up the settings.py file on pythonanywhere, and copy and paste into here what it says for ALLOWED_HOSTS?

You hit the nail on the head!

ALLOWED_HOSTS = ['127.0.0.1', '<your_username>.pythonanywhere.com']

I had to replace <your-username> with my username. Thanks so much!

I didn't know that the settings file online could be different. Do you know why that happened?

Because locally you're running the dev server or with debug enabled.

So if I set DEBUG = False, that would also work? Isn't that an important security feature?

What do you mean when you say I'm running the dev server locally - as in, on my system? Even though I updated the settings.py on my computer, the changes didn't get reflected in the settings.py file on PythonAnywhere...?

Thanks for your help Harry, and thank you too Glenn, for your explanation! I appreciate it.

Yes, DEBUG=False is an important security feature and so is ALLOWED_HOSTS.

I assumed that you were wondering about why you got the ALLOWED_HOSTS error on PythonAnywhere and not when you were working on your machine.

How did you resolve this? I am too having the same problem. I am deploying my app for the first time and it is throwing the same error even after adding the same in setting.py

I don't get that error when I go to http://prem2282.pythonanywhere.com/ -- did you work out what the problem was?

please elaborate the solution i cann't get it work.

Are you running django?

Yes, i am running on django and getting the same error can someone help me out

How does your ALLOWED_HOSTS look like?

Getting the same error, even after adding my url to the allowed_hosts line; also followed every advice here, please assist.

What is the exact line that you added to the ALLOWED_HOSTS line, and what is the full error message that you're getting on your site?

thanks for asking, I resolved the issue. Thanks again.

OK, glad to hear you worked it out!