I'm using django's builtin server to develop a site and I want other computers in the same network I'm on to be able to access the server using the local IP address. I have seen many posts about this and after trying all suggestions it's still not allowing other computers in my network to access the site.
I run the server using
python manage.py runserver 0.0.0.0:8000
and have already opened port 8000
as you can see in the following image.
I'm running Django 1.4.2, Python 2.7.3, Fedora 18 on kernel 3.8.11-200
Any help is highly appreciated. Thanks.
Use python manage.py runserver <ip>:<port>
For example,my IP is 192.168.0.100 and I want to run django app on port 80,I have to do
[sudo] python manage.py runserver 192.168.0.100:80
My port 80 needed root permissions,maybe because I have other applications accessing it.
You also have to add the IP address to ALLOWED_HOSTS
list in settings.py
By doing this all clients in the 192.168.0 network will be able to access the site at 192.168.0.100
You're starting Django as needed - it will accept connections from anywhere as soon as the connections get to it.
Check your firewall and make sure it's allowing 8000 port connections. Something like this should work:
iptables -I INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
Optionally you will need to extend the INTERNAL_IPS
variable in the setting to allow remote debugging: https://docs.djangoproject.com/en/dev/ref/settings/#internal-ips .
skarap is correct. If your network is configured correctly and your django application with pytho9n manage.py runserver 0.0.0.0:8000 and you still can't access your django app from the VM host there is almost certainly a firewall issue. The illustration above is good if you are running iptables.
I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.
if
ps -ae | grep firewall returns something like 602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct you VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent firewall-cmd --reload
Many thanks to pablo v on the http://www.scriptscoop.net site for pointing this out.
You have to add the server IP to the ALLOWED_HOSTS in the settings.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With