[Django]-Can't access my laptop's localhost through an Android app

6👍

Have you started the server like this?

python manage.py runserver 0.0.0.0:8000

Then, try to connect to 192.168.XXX.XXX:8000

2👍

I tried the above, but failed to work in my case. Then with running
python manage.py runserver 0.0.0.0:8000 I also had to add my IP to ALLOWED_HOSTS in settings.py, which solved this issue.

eg.
Add your ip to allowed hosts in settings.py
ALLOWED_HOSTS = [‘192.168.XXX.XXX’]

Then run the server
python manage.py runserver 0.0.0.0:8000

0👍

Others have already given the answer but those solutions didn’t work for me when I was running Django server on Ubuntu and was trying to access it from my Mobile app.

Following is what worked for me:

Step 1: Run server to access it from your IP

python manage.py runserver 0.0.0.0:8000

Step 2: Open port in firewall (Missing step in above given answers – Needed for Ubuntu)

$ sudo ufw enable 
$ sudo ufw allow 8000

Leave a comment