How to create a local network (intranet) with django? [closed]

closed . This question needs details or to be clearer and is not currently accepting answers.

want to improve this question? Add details and make it clearer what problem is being solved by editing this post .

Closed 2 years ago .

improve this question

I'm breaking my head, I've tested several and several gringos tutorials and nothing works with excellence. I have a system made in django in a common computer (windows 10) and I'm trying to leave localhost open for the other computers on the network to access the application. I have done several and several attempts but nothing works round, because with php it is so simple....

Thank you, right now.

Author: Pedro von Hertwig Batista, 2018-07-03

1 answers

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 connections from your machine's local IP. This your IP, if it is on Windows, can be found with the command ipconfig. It will be under the "IPv4 Address" field and will be in the format 192.168.x.x or 10.0.x.x. You can also find out by going to your router's page, probably under the DHCP settings.

At this point, if you try accessing this your IP from your computer or another that is on the local network, you will discover a message from Django with the following sayings (for my case, in which 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 row containing the variable looked like this:

ALLOWED_HOSTS = ['192.168.15.14']

You can now access your website normally through your own computer or other devices present on the same local network by typing this IP in the address bar of the browser. If you can access from your computer but not from others, it is probably a firewall that is blocking access. Check your computer's firewall settings and try again.

I recommend that you set a fixed IP on your router for the machine that will host the site. So you won't have to mess around with ALLOWED_HOSTS or check which is the your IP if the router assigns a different IP to your computer after a while, as is not infrequently the case when the configuration is DHCP.

 1
Author: Pedro von Hertwig Batista, 2018-07-03 20:14:27