Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

558
Visualizações
Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS

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.

over 4 years ago · Santiago Trujillo
5 Respostas
Responde à pergunta

0

You have to find your device ip address from where you are running the django app.

How to find the local ip address

To use django on local network Run command python manage.py runserver 0.0.0.0:8000

To run on other device connected to same local network you have to type ip address of your server device from where you are running django app.

192.168.1.1:8000/ # this is just dummy example.

Its should work as far both devices are connected to same network. And firewall is allowed.

over 4 years ago · Santiago Trujillo Relatório

0

I just added the ip in ALLOWED_HOSTS property in the file <your_app_path>/settings.py.

e.g.

...
ALLOWED_HOSTS = ['0.0.0.0']
...

And it worked fine.

over 4 years ago · Santiago Trujillo Relatório

0

ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', '*').split()

I'm just added split() because without split() it just localhost 127.0.0.1 0.0.0.0 [::1] for django need the list.

over 4 years ago · Santiago Trujillo Relatório

0

in settings.py, change
ALLOWED_HOSTS = ['*']
this work for me, *represent the all the ports can have access to the site

over 4 years ago · Santiago Trujillo Relatório

0

Take a look at settings.py and fill the ALLOWED_HOSTS as follows. For local host:

ALLOWED_HOSTS = ["0.0.0.0"]

OR you can do

ALLOWED_HOSTS = ["*"]

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda