PythonAnywhere 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.