1

I have a Django server running on 127.0.0.1:8000

When I try to access it from the same machine then I am able to open my application. But when I try to access this app from a different machine by using machinename:8000 then it says 'This site can't be reached'

In my settings.py, I have

ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())

and

ALLOWED_HOSTS=

Is this related to above configuration?

ThinkGeek
  • 4,749
  • 13
  • 44
  • 91
  • running your server on `127.0.0.1:8000` makes it only available on the local host. You can run the server on `0.0.0.0:8000` for example, to make it available for another machine of the network – PRMoureu Aug 18 '19 at 13:22
  • If your django server is listening on `127.0.0.1` (the loopback interface) then you can't access it from outside the same machine. If you want the app to be reachable from other machines in the same network, make your app listen on `0.0.0.0` (all interfaces) & use the IP of the host machine to connect – rdas Aug 18 '19 at 13:22
  • Changing it to 0.0.0.0:8000 says - DisallowedHost at / Invalid HTTP_HOST header: 'garuda10.hyd.amzn.co:8000'. You may need to add u'garuda10.hyd.amzn.co:8000' to ALLOWED_HOSTS. – ThinkGeek Aug 18 '19 at 13:26

1 Answers1

3

To connect with the other computers in the same local network as you you have to run your sever using :

manage.py runserver 0.0.0.0:8000

And in your settings.py put :

ALLOWED_HOSTS = ['*']

And you have to know your local IP adress of your pc and connect adding ":8000" at the end. To know your computer IP adress: Bash : $ ifconfig Windows : ipconfig

veksor
  • 302
  • 1
  • 7
  • I did this, but when I start server by using "python manage.py runserver 0.0.0.0:8000" it says Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS. – ThinkGeek Aug 18 '19 at 14:07
  • Did you try with this ALLOWED_HOSTS = ['0.0.0.0', 'localhost', '127.0.0.1'] ? If it's not working you check the [Documentation](https://docs.djangoproject.com/en/1.10/ref/settings/#allowed-hosts) – veksor Aug 18 '19 at 14:15
  • 1
    Are you sure that : --> devices are in the same network / The IP you try is your server/pc IP / You add ":8000" at the end of the address – veksor Aug 19 '19 at 09:48