Aaron Cloud
Aaron Cloud

Reputation: 315

How do I make Django Website public on my local network?

I am building a website for myself and family in Django and React. Every time I ask them to check my process and get their opinions they get a webpage not found error or this site can't be reached. How do I make is so that anyone on my local network can check my page when its running. This is the default in flask, I don't understand why django runs like this? (safety maybe?) I can't find any good information on how to add an allow all to the ALLOWED_HOSTS section in the settings of the main app.

I also know that you can add IP address, But I'm a noob and I don't follow how to get the ip address of all my families devices without alot of work?? Does anyone have a good solution for this??

Upvotes: 2

Views: 6960

Answers (4)

stifler
stifler

Reputation: 21

It is very simple

  1. just go to your command line and type ipconfig if its windows and ifconfig if it is linux
  2. Note your ip address on your local network
  3. Write that address in allowed hosts in settings.py
  4. Run command python manage.py runserver :
  5. Take any device connect to your local network and in its browser window type servers ip:port number For eg 192.168.25.1:8080

Upvotes: 2

mndv
mndv

Reputation: 130

Django documentation:

When DEBUG is True and ALLOWED_HOSTS is empty, the host is validated against ['.localhost', '127.0.0.1', '[::1]'].

If you are in debug mode with an empty list, or in non-debug mode also with an empty list, no one in your LAN network could be accessed to your website.

In this case, because you are in a LAN, you could use:

ALLOWED_HOSTS = ['*']

Then run

python manage.py runserver 0.0.0.0:8000

You don't need to open any ports on your router if you are in LAN, but maybe you need to configure your firewall in your local machine.

Otherwise, a web server like nginx or apache is recommended.

Upvotes: 3

Al W
Al W

Reputation: 7713

ALLOWED_HOSTS = ['*']

But this is not your real problem. You'll most likely need to open ports in the firewall of either your local machine or your router (or both) before other machines on the network will be able to reach yours.

Upvotes: 1

Mohamed ElKalioby
Mohamed ElKalioby

Reputation: 2334

If all are on the same network then run

python manage.py runserver 0.0.0.0:8000

Upvotes: 1

Related Questions