Search code examples
djangoconnection-refused

Django trying to access the site results in connection-refused


I am trying to access my site from my phone. Both my laptop and phone connected to the same wifi network. I tried to access the website with Postman and got a successful response. However when I try to access the site from my phone I get ERR_CONNECTION_REFUSED. What can be the reason for this? I use this test url that I know works: http://127.0.0.1:8000/policies/myModels_asJson


Solution

  • 127.0.0.1 is the localhost so unless you're running your django app (or at least a webserver) on your phone that's the expected result.

    If you want to test from your phone, you must

    1. make sure the django server on your laptop (I assume it's running on the laptop) listens on the laptop's own ip (which should be a local ip in the 192.168.* range) - the simplest here is to run it on 0.0.0.0 (which means "listen on all ips"): ./manage.py runserver 0.0.0.0:8000

    2. point your phone's browser to your laptop's local ip