Django and runserver 0.0.0.0
I’ve been trying to figure out how best to access my local Django dev server from other machines on my network. Now I seem to have found an answer.
What I was doing
Running with just:
only makes the system available via localhost which is of course useless for other machines on the network. To solve this I was looking up the ip for my machine and passing that to runsever:
manage.py runserver 192.168.10.2:8000
That works for the most part but now I also have to use the ip in the url (localhost doesn’t work anymore). Also for some reason this was not accessible from my iPhone or iPad which makes testing on them harder. (I think this is because of my network setup since I have different subnets).
After putting up with this for a while I started looking around for a better way to handle this and I found it!
The better way
From searching I found this Django ticket (#396) which has a very interesting comment
Use runserver 0.0.0.0:8000 to make it listen on all interfaces
Could it really be that simple? So I tried it out and yep it totally is.
manage.py runserver 0.0.0.0:8000
Now I can access my Django dev server using localhost on the local machine, my ip address from other machines and even
my_machine_name.local:8000 from my iPhone or iPad. Awesome.
You might want to be careful how you use this since you are obviously allowing access from way more places but for myself (and I’m guessing a lot of others) this is far more convenient. I was using a bash alias to launch runserver with my ip address. I’ll be changing that over to this method right away.