How to create a local network (intranet) with Django?

Asked

Viewed 2,052 times

0

I’m racking my brain, I’ve tried several and several tutorials gringos and nothing works with excellence. I have a system made in Django on a common computer (windows 10) and I’m trying to leave the localhost open for other computers in the network to access the application. I have made several and several attempts but nothing works round, because with php is so simple....

Grateful, from now on.

  • 2

    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.

1 answer

1


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.

  • 1

    Partner, thanks EVEN. I even did dual boot with a Ubuntu to create a real server in it! Good guy, sent benzasso! Take +1 and a cup, that’s what I can offer only kkkkk, thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.