[Django]-How to access my 127.0.0.1:8000 from Android tablet

16đź‘Ť

âś…

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.

👤bojangler

36đź‘Ť

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.

👤cwallenpoole

26đź‘Ť

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.

  1. Add ALLOWED_HOSTS = ['*'] in django settings.py file

  2. run django server with python manage.py 0.0.0.0:YOUR_PORT. I used 9595 as my port.

  3. 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 connections

    • hit next again then give it a name and hit next for the last time.

  4. 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.
  5. Now from another device (pc, mobile, tablet etc.) connected to the same network go to ip_address:YOUR_PORT (in my case 192.168.0.100:9595)

    Hopefully you’ll be good to go !

👤foysal

6đź‘Ť

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.

👤DevOfZot

2đź‘Ť

need to know the ip address of your machine ..
Make sure both of your machines (tablet and computer) connected to same network

192.168.0.22 – say your machine address

do this :

192.168.0.22:8000 — from your tablet

this is it !!!

👤Manuj Rastogi

1đź‘Ť

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.

👤smk

0đź‘Ť

Tested using easy EasyPHP DevServer 14.1.
The trick is you must first add your local ip address to the Apache server to listen to it.

Right click on the tray icon, go to “Configuration” -> “Apache” in the “httpd.config”

# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 127.0.0.1:80
Listen 192.168.0.201:80  <<-- ADD THIS LINE

Then go to your Control Panel and deactivate your Windows Firewall or add your Smartphone/Tablet Ip Address to the exception.

That’s it. I hope it helps.

The IP Address 192.168.0.201 may be different from yours. 192.168.0.X

👤Tower Jimmy

0đź‘Ť

I’ve struggled with this problem myself, and I couldn’t figure out what it was, since it worked perfectly on my iPhone, I decided to look into the problem and find a quick solution.
My local machine is a Mac OSX 10.10+, one option would have been to start an Apache server, but that’s super unhandy – changing the DocumentRoot every time you want to check something quickly on your Android device. Besides that, changing the DocumentRoot is a pain in the a** on Mac OSX 10.10.

If you want to use:

python -m SimpleHTTPServer

on your Android, do this:

sudo python -m SimpleHTTPServer [ANY PORT YOU WANT, BUT NOT 8000]
👤pit tanenbaum

0đź‘Ť

Try this
python manage.py runserver
then connect both tablet and system to same wifi and browse in the address
eg: python manage.py runserver 192.168.0.100:8000
In tablet type that url in adress bar

👤Jayas P Jacob

0đź‘Ť

In my case I was required to disconnect and reconnect to the same network (both phone and pc), after changing the firewall settings.

👤Saurabh Mahra

0đź‘Ť

Same as @foysal, but I had Visual studio code and python Forbidden in inbound rules, so I marked them available for all connections

-1đź‘Ť

I had the same problem on android and emulator and this is how i solved it

1) Make sure run server on 0.0.0.0
this make accessible on emulator and android devices

in terminal: python manage.py runserver 0.0.0.0:8000

in PyCharm: edit configuration -> put 0.0.0.0 in Host

2) Find PC IP address with ipconfig command and copy IPV4
enter image description here

3) Add ipv4 to ALLOWED_HOST in django settings.py

4) IF YOU USE WINDOW make sure disable windows defender firewall

disable windows defender firewall

5) double check that your computer and your device(mobile) using the same WIFI

👤Radesh

Leave a comment