Instead of running
python manage.py runserver
Perform the following:
python manage.py runserver 0.0.0.0:80
This instructs Django to open the server and accept local IP connections from your machine. That your IP, if it is in Windows, can be found with the command ipconfig
. It will be under the field "Ipv4 Address" and will have the format 192.168.x.x
or 10.0.x.x
. You can also find it by accessing your router page, probably under the DHCP settings.
At this point, if you try to access your IP from your computer or from another on the local network, you will find a message from Django with the following words (for my case, where my local IP is 192.168.15.14
):
Invalid HTTP_HOST header: '192.168.15.14'. You may need to add '192.168.15.14' to ALLOWED_HOSTS
This is a security feature of Django. Just obey the message and add your IP to the list ALLOWED_HOSTS
present in your settings.py
.
In my case, the line containing the variable was like this:
ALLOWED_HOSTS = ['192.168.15.14']
You can now access your website normally via your own computer or other devices present on the same local network by entering this IP in the browser’s address bar. If you can access it from your computer but not from others, it’s probably a firewall that’s blocking access. Check your computer’s firewall settings and try again.
I recommend that you set up a fixed IP on your router for the machine that hosts the site. So, you won’t have to touch the ALLOWED_HOSTS
nor verify what your IP is if the router assigns a different IP to your computer after a while, as not infrequently occurs when the setting is DHCP.
Could you list these attempts and describe what the results were? This will prevent people from helping you to test solutions in vain. Or even better, they can point out the possible solutions to make work what you have tested and done.
– Woss