Question

Django 3.2 LTS ALLOWED_HOSTS

Hi, I am a novice. I have installed django from the 1 click marketplace. I am getting the response from the ip url. Have added domain name and no problem ssh to the server. I have edited the settings and added the domain name but still getting: Invalid HTTP_HOST header: ‘www.mydomain.com’. You may need to add ‘www.mydomain.com’ to ALLOWED_HOSTS

Below is the setting.py:

def ip_addresses():
    ip_list = ['159.223.76.95', '2400:6180:0:d0::fb9:8001']
    for interface in netifaces.interfaces():
        addrs = netifaces.ifaddresses(interface)
        for x in (netifaces.AF_INET, netifaces.AF_INET6):
            if x in addrs:
                ip_list.append(addrs[x][0]['addr'])
    return ip_list

ALLOWED_HOSTS = ip_addresses('www.mydomain.com')

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @devrroslan,

So basically, you need to have the following:

ALLOWED_HOSTS = ['<domain name>', '<Ip address>']

I see you’ve created a function that takes a list of IP addresses but I’m not sure if it will run that way. Make sure to include the domain as well like the above.

Additionally, don’t forget to restart your gunicorn application after each change otherwise it won’t take it up.