[Python] Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to...

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    Django does not seem to find my host 0.0.0.0

    I have already added "0.0.0.0" to my ALLOWED_HOSTS. In fact, if I print(ALLOWED_HOSTS) I get ['localhost', '127.0.0.1', '0.0.0.0', '[::1]']. I am working in docker. Is there anything I am overlooking?

    .env.dev


    DEBUG=1
    SECRET_KEY=foo
    DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0 [::1]
    SQL_ENGINE=django.db.backends.postgresql
    SQL_DATABASE=xxxx
    SQL_USER=xxxx
    SQL_PASSWORD=xxxx
    SQL_HOST=db
    SQL_PORT=5432
    DATABASE=postgres


    env_settings.py

    import os

    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = os.environ.get("SECRET_KEY")

    # SECURITY WARNING: don't run with debug turned on in production!
    # DEBUG = True
    DEBUG = int(os.environ.get("DEBUG", default=0))

    ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


    settings.py

    from core.env_settings import *

    print(ALLOWED_HOSTS)

    """
    print(ALLOWED_HOSTS) returns ['localhost', '127.0.0.1', '0.0.0.0', '[::1]']
    """


    NB: I have carefully reviewed all similar questions posted here and there's none with this specific problem.

    Continue reading...

Compartilhe esta Página