how to access my 127.0.0.1:8000 from android tablet
Solution 1
You can find out what the ip address of your PC is with the ipconfig
command in a Windows command prompt. Since you mentioned them being connected over WiFi look for the IP address of the wireless adapter.
Since the tablet is also in this same WiFi network, you can just type that address into your tablet's browser, with the :8000 appended to it and it should pull up the page.
Solution 2
So, there are a couple of issues it seems. The question most of the answers are addressing is "how do you connect to another server in your local network?" (or variants). There are two answers, you can use the computer's IP directly, or you can use the computer's name (you may need to append .local
). For example, my computer is xavier.local
.
The second issue is that you seem to be addressing is that runserver
is not accessible via other computers on the network (this is your actual question). The reason is that by default Django's runserver will only acknowledge requests from the machine which is calling them. This means that the default settings would make it so that you would only be able to access the server from Windows (and they did this on purpose for security reasons). In order for it to listen to other requests you have two options:
runserver 192.168.1.101:8000
# Only handle requests which are made to the IP address 192.168.1.101
Or (and this is easier when dealing with more than one environment):
runserver 0.0.0.0:8000 # handle all requests
So, if your IP address is 192.168.1.101:
runserver # only requests made on the machine will be handled
runserver 127.0.0.1 # only requests made on the machine will be handled
runserver 192.168.1.101 # handles all requests (unless IP changes)
runserver 192.168.1.100 # does not handle any requests (wrong IP)
runserver 0.0.0.0 # handles all requests (even if the IP changes)
I do think it important to note that 0.0.0.0
is realistically not a security question when dealing with a local, development machine. It only becomes a significant problem when working on a large app with a machine which can be addressed from the outside world. Unless you have port forwarding (I do), or something wonky like that, you should not be too concerned.
Solution 3
Though this thread was active quite a long time ago. This is what worked for me on windows 10. Posting it in details. Might be helpful for the newbies like me.
Add
ALLOWED_HOSTS = ['*']
in djangosettings.py
filerun django server with
python manage.py 0.0.0.0:YOUR_PORT
. I used9595
as my port.Make firewall to allow access on that port:
Navigate to control panel -> system and Security -> Windows Defender Firewall
Open Advanced Settings, select Inbound Rules then right click on it and then select New Rule
Select Port, hit next, input the port you used (in my case
9595
), hit next, select allow the connectionshit next again then give it a name and hit next for the last time.
Now find the ip address of your PC.
- Open Command Promt as adminstrator and run
ipconfig
command. - You may find more than one ip addresses. As I'm connected through wifi I took the one under Wireless LAN adapter WiFi. In my case it was
192.168.0.100
- Note that this ip may change when you reconnect to the network. So you need to check it again then.
- Open Command Promt as adminstrator and run
Now from another device (pc, mobile, tablet etc.) connected to the same network go to
ip_address:YOUR_PORT
(in my case192.168.0.100:9595
)Hopefully you'll be good to go !
Solution 4
127.0.0.1
is a loopback address that means, roughly, "this device"; your PC and your android tablet are separate devices, so each of them has its own 127.0.0.1
. In other words, if you try to go to 127.0.0.1
on your Android tab, it's trying to connect to a webserver on the Android device, which is not what you want.
However, you should be able to connect over the wifi. On your windows box, open a command prompt and execute ipconfig
. Somewhere in the output should be your windows box's address, probably 192.168.1.100
or something similar. You tablet should be able to see the Django server at that address.
Solution 5
If both are connected to the same network, all you need to do is provide the IP address of your server (in your network) in your Android app.
doniyor
Python Developer, Django Developer, Fullstack. Ideas. World. Changes. Trace.
Updated on August 17, 2021Comments
-
doniyor almost 3 years
I am developing a webpage in django (on my pc with windows 7) and now i need to test some pages in tablet pcs. suddenly the thought came if i can have an access to my localhost in windows from android tablet. is that possible? I am in the same wifi connection in both devices at home.
i read a lot questions and answers regarding this issue in stackoverflow and other places, but none of them gave me some concrete solutions.
I have samsung tab 2 10.1 with android 4.0.4.
appreciate any help, thanks