Reputation: 155
I cannot access localhost / 0.0.0.0:8000 from any other device.
The current django project is built off of an older project I was playing around with last year where this worked. Unfortunately i've lost the previous project so I cannot compare their settings.py files, although there should be hardly any difference between them.
.
The setup
.
Where the problem is
The fault must be on my laptop where the server is running because I cannot access the server on either my desktop nor my iPhone, the latter worked last year with the previous project, I did not have my desktop at the time.
.
The project's allowed hosts list
I've added several as i've been trying out different solutions recommended by others.
ALLOWED_HOSTS = [
'*',
'0.0.0.0.',
'0.0.0.0:8000',
'localhost'
'localhost:8000'
'{laptop's IP address}',
'{desktop's IPv4 address}',
'{desktop's Default gateway}',
]
.
When I try to access the localhost on desktop or iPhone
Nothing appears in the laptop's terminal, the quit server help line remains the last line. I remember last year, it would update with notifcations that something remotely was accessing the server.
On the desktop, Firefox tells me it's 'Unable to connect', Edge tells me 'localhost refused to connect' with a 'ERR_CONNECTION_REFUSED'.
On the iPhone, 'could not connect to the server'.
.
what I've tried in the other devices' URL address bar
.
.
Any help would be appreciated.
Upvotes: 2
Views: 2727
Reputation: 2798
To host on a local network, first ensure that your IP address is added to the ALLOWED_HOSTS
of settings.py
.
ALLOWED_HOSTS = ['192.168.1.X']
Note: Your IP address can be locate via running
ipconfig
in the command prompt
Ensure you also execute runserver
on ip address 0.0.0.0:8000
. For example:
python manage.py runserver 0.0.0.0:8000
When connecting with other devices put the IP address and the port number of the host in the URL within the browser. Like so:
192.168.1.X:8000/<app_name>/other_pages
Upvotes: 2