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.
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.
- [Django]-Use Python standard logging in Celery
- [Django]-Django npm and node packages architecture
- [Django]-What is the equivalent of "none" in django templates?
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.
-
Add
ALLOWED_HOSTS = ['*']
in djangosettings.py
file -
run 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 connections -
hit 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 !
- [Django]-How to update fields in a model without creating a new record in django?
- [Django]-Why does django ORM's `save` method not return the saved object?
- [Django]-How do you log server errors on django sites
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.
- [Django]-Python- How to flush the log? (django)
- [Django]-What is the purpose of apps.py in Django 1.9?
- [Django]-Django 1.7 – "No migrations to apply" when run migrate after makemigrations
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 !!!
- [Django]-How to use environment variables with supervisor, gunicorn and django (1.6)
- [Django]-Django 1.7 – How do I suppress "(1_6.W001) Some project unittests may not execute as expected."?
- [Django]-Django: Want to display an empty field as blank rather displaying None
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.
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-Models.py getting huge, what is the best way to break it up?
- [Django]-Django Rest Framework: Disable field update after object is created
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
- [Django]-Unable to import path from django.urls
- [Django]-How do you convert a PIL `Image` to a Django `File`?
- [Django]-My django template boolean variable isn't working as expected in javascript
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]
- [Django]-Getting a list of errors in a Django form
- [Django]-Django queryset filter for blank FileField?
- [Django]-Django: Use of DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT in settings.py?
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
- [Django]-Why does Django's render() function need the "request" argument?
- [Django]-What is related_name used for?
- [Django]-"Post Image data using POSTMAN"
0đź‘Ť
In my case I was required to disconnect and reconnect to the same network (both phone and pc), after changing the firewall settings.
- [Django]-Django ORM and locking table
- [Django]-Can't compare naive and aware datetime.now() <= challenge.datetime_end
- [Django]-How to add custom search box in Django-admin?
0đź‘Ť
Same as @foysal, but I had Visual studio code and python Forbidden in inbound rules, so I marked them available for all connections
- [Django]-How to suppress the deprecation warnings in Django?
- [Django]-How to test custom template tags in Django?
- [Django]-Using JSON in django template
-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
3) Add ipv4 to ALLOWED_HOST in django settings.py
4) IF YOU USE WINDOW make sure disable windows defender firewall
5) double check that your computer and your device(mobile) using the same WIFI
- [Django]-How to set up Django website with jQuery
- [Django]-Django, how to remove the blank choice from the choicefield in modelform?
- [Django]-Django 1.5b1: executing django-admin.py causes "No module named settings" error