2

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

  • Dropbox - holds project and sqlite database file
  • Laptop - running server, had no changes over last year
  • Desktop - /
  • iPhone - /

.

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

  • 0.0.0.0:8000
  • localhost:8000
  • localhost:8000/admin
  • https://{laptop IP address}

.

.

Any help would be appreciated.

4
  • What are you entering into the browser url on other devices to access the site? Commented Aug 9, 2021 at 14:27
  • I've updated my answer but then started playing around with different things. Your question put me on the right path, it now works. I had to enter the laptop's IP address, followed by ':8000/admin'. If you suggest this as the answer, i'll accept it and give you the points. Commented Aug 9, 2021 at 15:11
  • Yeah that's it the PC IP address of the Host. I had this problem way back when I first started so I could test page responsiveness on different aspect ratio devices at home. Glad it help! Commented Aug 10, 2021 at 10:48
  • 1
    No problem, do you want to write this as a proper answer and I'll accept it. Commented Aug 10, 2021 at 11:24

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for help, if you have time I'd appreciate you taking a look at stackoverflow.com/questions/68719966/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.