views:

823

answers:

1

This is only marginally a programming problem and more of a networking problem.

I'm trying to get a Django web app to run in my home network and I can't get any machines on the network to get to the web page. I've run on ports 80 and 8000 with no luck. Error message is: "Firefox can't establish a connection to the server at 192.168.x.x."

I've tried using sockets in python from the client:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect ( ("192.168.x.x", 80) )

I just get "socket.error (10061, 'Connection refused')". Interestingly, I can connect with port 25.

There is no Windows firewall running. There is a NetGear router/firewall in front of the cable modem.

What should I be looking at to configure this?


Also tried:

import urllib2
urllib2.urlopen("http://192.168.x.x/")

Same thing.


Re: "Can you see the Django app from the machine it's running on?"

Yes. It does work on the same machine. It does not work across the network.

I can also set the server to run on whatever port I choose (80, 8000, etc.) and it is accessible locally, not across the network.


Q. Is it netstat-able? A. Yes:

  Proto  Local Address          Foreign Address        State
  ....
  TCP    D3FL2J71:http          localhost:1140         TIME_WAIT
  TCP    D3FL2J71:http          localhost:1147         TIME_WAIT

I have the website visible in two browser windows locally.


Use explicit external port (not rely on localhost):

python manage.py runserver 192.168.x.x:8000

Bing bing bing! We have a winner!

Wow, am I ever glad this is not a networking problem.


"is the Django app definitely advertising itself on the 192.168.x.x address and not just on the loopback adapter?"

It seems Jon was on the right track, too, but the comment did not point me in the direction to look -- check the Django server's setup call.

+3  A: 

I assume you're running the django dev server? If so, make sure you start it so that it will bind to the IP address the other machines need to use for the connection:

python manage.py runserver 192.168.x.x:8000

You can ask the server to bind to all addresses with (haven't tried this on Windows myself, I admit):

python manage.py runserver 0.0.0.0:8000

Normal runserver usage binds only to localhost, I'm afraid.

Jarret Hardie
Re: "Normal runserver usage binds only to localhost, I'm afraid."Famous last words.
hughdbrown