Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Django devserver from another machine same network

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.

enter image description here

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.

like image 358
Paulo Avatar asked May 12 '13 04:05

Paulo


4 Answers

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

like image 121
rjv Avatar answered Oct 07 '22 15:10

rjv


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 .

like image 44
skarap Avatar answered Oct 07 '22 15:10

skarap


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.

like image 38
lamwilli Avatar answered Oct 07 '22 14:10

lamwilli


You have to add the server IP to the ALLOWED_HOSTS in the settings.py

like image 1
Raul Coelho Avatar answered Oct 07 '22 14:10

Raul Coelho