0

I am developing an android app. For local testing I have created a django server on my laptop. My problem is I am not able to call django apis from app code. For example, if I want to call any django server api from desktop I write "localhost:8000/polls/link/2/". Now how to replace this "localhost part of url" if calling same api from mobile. And also my desktop is connected to internet by the same mobile hotspot. So basically both desktop and phone are on same network. My ifconfig command on desktop shows

And my desktop is Mac and mobile is Samsung core duo

Utkarsh Srivastav
  • 2,905
  • 7
  • 33
  • 53

6 Answers6

3

For developing you can use your device's inner IP address

in terminal: $ ifconfig | grep inet

you will get: inet addr:10.0.0.1 ...... use that ip with django runserver

$ python manage.py runserver 10.0.0.1:8000

from android use:

"http://10.0.0.1:8000/" as your url String

Rubber Duck
  • 3,484
  • 3
  • 31
  • 52
0

can you see the index.html on your phone browser?

localhostIP:8000

if you can, then all should be fine, if not, there is a configuration issue,

is your website on your local server accessible from the outside? How to access the local Django webserver from outside world

good luck

Community
  • 1
  • 1
manuelBetancurt
  • 14,346
  • 29
  • 109
  • 206
0

If I understand your question correctly, you have a Django installation on your laptop and you are able to hit a specific page/service locally using "localhost:8000/polls/link/2/" and it works fine. Now you want to access it from your mobile. Correct?

Replace the "localhost" with IP address of your laptop. For example, "10.0.0.1:8000/polls/link/2/"

You will find your IP address in System Preferences -> Network

MirekE
  • 11,355
  • 5
  • 33
  • 27
0

You have to set multiple things for access your API at your local network.

  1. Go to terminal and type ifconfig and get your inet address.

  2. Then add this inet address in allow_host of your project setting.py file.

  3. Start your server by using command ---> python manage.py runserver 0.0.0.0:8001 or any other port which is free.

I am assuming your inet address is 192.168.1.10

Then go to your browser and type

192.168.1.10:8001/your_app_name/your_url_of_view
GhostCat
  • 133,361
  • 24
  • 165
  • 234
Sajid
  • 21
  • 1
  • 5
0

Firstly run the django server by typing python manage.py runserver 0.0.0.0:8000. Then check the ip of your private network i.e wlan ip using ifconfig command then simply replace your localhost text with that ip while calling API.

But above all make sure that your phone and lappy should be in same network.

-1

Have you try this?
or checking firewall options.

manage.py runserver 0.0.0.0:8000
asf
  • 5
  • 1
  • 4