ALLOWED_HOSTS and Django

Alex picture Alex · Jul 19, 2017 · Viewed 45k times · Source

I tried to launch a Django 1.11 project on production server. When I start the app I see the following error:

Invalid HTTP_HOST header: 'bla-bla-bla.bla-bla-vla.com'. You may need to add u'bla-bla-bla.bla-bla-vla.com' to ALLOWED_HOSTS**

But, host "bla-bla-bla.bla-bla-vla.com" has been added to ALLOWED_HOSTS in settings.py already!

I tried to switch DEBUG from False to True and back. It works fine, then.

What am I doing wrong?

Answer

RompePC picture RompePC · Jul 19, 2017

If Django says:

Invalid HTTP_HOST header: 'bla-bla-bla.bla-bla-vla.com'. You may need to add u'bla-bla-bla.bla-bla-vla.com' to ALLOWED_HOSTS

then you need to add bla-bla-bla.bla-bla-vla.com, literally (or using a dot as a wildcard) to ALLOWED_HOSTS (docs).

Then reload Apache2 (not restart, reload) to verify changes have applied.