Django development server on Raspberry Pi refuses connection

1

1

I have a simple web service running on my Raspberry Pi, using the Django development server (manage.py runserver). I know it's working, because when I run curl localhost:8000 on the Pi, I get the HTML contents of my website. When I run netstat -tnl on the pi, I get the following:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN 

However, when I try to connect to the website from a different computer on the same local network as the Pi (using http://<local IP of the pi>:8000), I get connection refused. (I've tried both curl and a web browser.)

I connect to the Pi exclusively through SSH, and things like curl http://www.google.com work, so I know the Pi is connected to the network.

I have the most recent version of Raspbian on the Pi. (I just reinstalled it yesterday thinking that might fix this issue)

How can I connect to this website? Do I need to open a port on the Pi or something?

I am not interested in connecting to this web server outside of my local network, so I don't think I should have to deal with port forwarding.

ItsTimmy

Posted 2016-10-22T15:23:20.163

Reputation: 163

Try the following command to start your server: python manage.py runserver 0.0.0.0:8000 – None – 2016-10-22T17:26:54.167

Wow, that immediately fixed it. Why did that work? Oh, and would you please make that an answer so I can accept it? Thank you! – ItsTimmy – 2016-10-22T17:33:12.560

1I added an answer. – None – 2016-10-22T17:37:50.427

Answers

3

By default the Django development servers is bound to 127.0.0.1 as you can see in the Local Address field. It means that it only accepts connections from your Pi.

When you use 0.0.0.0 (Wikipedia), it is like a wildcard, it means that everyone on your local network can access it.

So in order to access your server from another machine you need to run the following command: python manage.py runserver 0.0.0.0:8000.

user615603

Posted 2016-10-22T15:23:20.163

Reputation: