Forums

ALLOWED_HOSTS error

Hii,

I followed the tutorial to the end, and i got this error after reloading it.

I checked the error log and this was the error: Invalid HTTP_HOST header: 'community.pythonanywhere.com'. You may need to add 'community.pythonanywhere.com' to ALLOWED_HOSTS.

What could have gone wrong ?

you need to add 'community.pythonanywhere.com' to ALLOWED_HOSTS in your settings.py file

i did that already. no result. still same thing

did you reload your webapp after makimg that chg?

+1 to what bfg says. If it's in settings.py, then it should work fine. One other thing to check -- ALLOWED_HOSTS is a list, so you should do this:

ALLOWED_HOSTS = ['community.pythonanywhere.com']

...and not this:

ALLOWED_HOSTS = 'community.pythonanywhere.com'

i think the django version over here is 1.1 and that is the reason

i think the django version over here is 1.1 and that is the reason

No, this is a separate issue.

you just need to go on web app and reload :)

Working with Mezzanine, there was a local_settings.py in addition to settings.py and it also had an ALLOWED_HOSTS environment variable. I had to put in my URL there, e.g. for OP, ['community.pythonanywhere.com']. local_settings.py was overwriting what settings.py had.

I had the same issue, then I added 'che1195.pythonanywhere.com' to the ALLOWED_HOSTS list in settings.py by editing the file directly in pythonanywhere.com.

This is probably not good practice, I originally tried editing settings.py directly on GitHub but I guess the changes don't automatically migrate to pythonanywhere.com. I am brand new to Git so I'm assuming there is a way of auto-updating source code changes, and I just haven't learned it yet.

yes- you should probably push the changes to github. This could occur either by

  • changing on PythonAnywhere, pushing it to github

or by:

  • changing locally, push to github, then pull it down on pythonanywhere

I hate updated my settings.py to have ALLOWED_HOSTS = ['mysite.pythonanywhere.com']

I pushed to github, then pulled to pythonanywhere. I then reloaded the webapp. Still receiving the same error. Is there anything else I can try?

DisallowedHost at / Invalid HTTP_HOST header: 'mysite.pythonanywhere.com'. You may need to add 'mysite.pythonanywhere.com' to ALLOWED_HOSTS.

Your site is showing up without an error at the moment -- did you work out what the problem was?

ALLOWED_HOSTS = ['yoursitename.pythonanywhere.com'] Do this After that go to web and then click reload..then it will work

Yes, exactly -- though of course you need to replace "yoursitename" with the actual name of your account on PythonAnywhere :-)