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

0

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

Thank you in advance.

    
asked by anonymous 03.07.2018 / 21:16

1 answer

1

Instead of running

python manage.py runserver

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

At this point, if you try to access your IP from your computer or another one on the local network, you will find a Django message with the following words (for my case, where my local IP is 192.168.15.14 ):

/ p>

  

Invalid HTTP_HOST header: '192.168.15.14'. You may need to add '192.168.15.14' to ALLOWED_HOSTS

This is a Django security feature. Just obey the message and add your IP to the ALLOWED_HOSTS list in your settings.py .

In my case, the line containing the variable looks like this:

ALLOWED_HOSTS = ['192.168.15.14']

You can now access your site normally through your own computer or other devices present on the same local network by typing this IP into 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 configure a fixed IP on your router for the machine that will host the site. So you will not have to tinker with ALLOWED_HOSTS or check what your IP is if the router assigns a different IP to your computer after a while, as it often does when the configuration is DHCP.

    
03.07.2018 / 22:14