How to connect from mobile phone to the localhost

I am developing a website on Django, the local version is run by development server (python manage.py runserver) on localhost. I can test my site in a browser, the address is http://127.0.0.1:8000/.

But now I need to see how my website is looking on the mobile phone. My laptop OS is Linux Mint, the phone OS is Android, both are connected to the WiFi router.

I tried this recipe. I found out my WLAN IP (by the command ifconfig), which happens to be 192.168.0.104. By the recipe, I should enter the address together with port number, which is, apparently, 8000 (according to the development server port, see the paragraph 1), so I should see my local website by the address 192.168.0.104:8000, both from the laptop and the phone browser. However, in both devices I get a following error (translated to English):

Can not connect. Firefox cannot establish a connection to the server at 192.168.0.104:8000. The site may be temporarily unavailable or too busy. Please try again in a few moments. If you cannot load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure Firefox has permission to access the web.

From the phone the error is similar:

This site can't be reached. 192.168.0.104 refused to connect. Try: checking the connection. ERR_CONNECTION_REFUSED

From this I conclude, that

  1. the address exists, but my device doesn't let me see it;
  2. the problem is not with the phone, it is somewhere in my laptop.

Here I stuck. There are three possible reasons in my mind:

  1. Linux firewall. I tried to disable it, but the result was the same;
  2. server settings. Here I'm lost. As I understand, I use Django runserver. But, interestingly, if I type on my phone only the IP without the port, I see the Apache2 Default Page. Suspect that my router can be working on its own Apache (?).
  3. router settings. Also I don't know where the problem could be.

Please help me with any ideas how to connect to the localhost from my phone. So far, I have to upload any tiny change on the deployment server and see my website from the phone through in the internet, which is very slow.

You can use ngrok to serve your project. connect ngrok to your project port and enter anywhere you want. for more read docs

add this 0.0.0.0:8000 to your runserver command.

python manage.py runserver 0.0.0.0:8000

And dev server should accept external request.

https://docs.djangoproject.com/en/5.0/ref/django-admin/#examples-of-using-different-ports-and-addresses

Back to Top