Access Django devserver from another machine same network

Solution 1:

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

Solution 2:

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 .

Solution 3:

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.