0

I have created an API named http://127.0.0.1:8000/event/allEvents and it works perfectly in my browser and on the Postman app.

However, when I am trying to access the API from another PC of the same network it return an error this site cannot be reached

Sohail Ahmad
  • 7,309
  • 5
  • 27
  • 46
  • 1
    how did you try from the *"other PC"*? which was the URL? – JPG Nov 25 '19 at 08:26
  • 1
    and when you run your application, try to set up ip 0.0.0.0 for example `./manage.py runserver 0.0.0.0:8000` – Brown Bear Nov 25 '19 at 08:33
  • http://127.0.0.1 is localhost , it say that it's using the ip of the currently using computer(in your case 127.0.0.1 is the computer that you using), what you searching for is [local network's IP](https://stackoverflow.com/a/19482207/11225821) – Linh Nguyen Nov 25 '19 at 08:40
  • Yes i'm using localhost hitiing this url `http://127.0.0.1:8000/event/allEvents` and its working fine where the server is running but not working to the other pc on same network – Sohail Ahmad Nov 25 '19 at 08:57
  • hitting this url on both browser and postman on other pc .. – Sohail Ahmad Nov 25 '19 at 08:58

2 Answers2

2

in your settings.py file add your local ip to allowed_hosts.for example:

ALLOWED_HOSTS = ['192.168.1.50']

and also run your local server using below command (set port number whatever you want):

python manage.py runserver 0:8080

and on browser at the other computer,call below url:

http://192.168.1.50:8080

IP address is your IPv4 Address 192.168.0.101 not the django default 127.0.0.1

Sohail Ahmad
  • 7,309
  • 5
  • 27
  • 46
Erfan
  • 379
  • 1
  • 6
0

Please modify your setting files and make changes to ALLOWED HOSTS.

for example:

ALLOWED_HOSTS = ['*'] #this will allow all the ip's in your local network to access your url ALLOWED_HOSTS = ['xx.xx.xx.xx'] # this will allow only "xx.xx.xx.xx" in your local network to access your url.

Ashish Kumar Verma
  • 1,322
  • 1
  • 13
  • 21