How to proper setup ALLOWED_HOST to allow other machine in the network access the web
Django server in machine TestPC-A , at 192.25.56.120
I want it accessible from the computer in the same network 192.25.56.xxx.
what I have configured
1. settings.py
ALLOWED_HOSTS = ["127.0.0.1", "localhost", "TestPC-A" , "0.0.0.0", "192.25.56.120"]
and this which i am not sure if this is necessary:
CSRF_TRUSTED_ORIGINS = [
"http://127.0.0.1",
"https://127.0.0.1",
"http://localhost",
"https://localhost",
"https://TestPC-A",
"http://TestPC-A",
]
2. runserver.bat
@echo off
REM Activate virtual environment in the current terminal session and run server
cmd /k ".venv\Scripts\activate && python manage.py runserver_plus --cert-file cert.pem --key-file key.pem 0.0.0.0:8000"
I have tried to add following in Windows hosts file C:\Windows\System32\drivers\etc\hosts
192.25.56.120 TestPC-A
I restart the server, and the web page is not loaded at another computer's web browser https://TestPC-A:8000/
What else that I need to set?
For posterity. To make your development server viewable to other machines on the network.
Suppose you have two machines machine A and machine B. Connect both machines to a common network (may even be your mobile phone’s wifi).
If machine A will be your server i.e. machine A is the machine where your source code has been all this while and machine A is where you have been running command:
python manage.py runserver
Check the IP address machine A was assigned on this network. [stackoverflow] Add this IP address to Django settings ALLOWED_HOSTS [django-docs] list so that Django will allow the machine to host it.
If the IP address is 172.200.42.1 for example, add this to ALLOWED_HOSTS and now run the command:
python manage.py runserver 0.0.0.0:7000 # <—- runserver on port 7000 on this host on this network
Since machine B is connected to the same network as machine A, use any http-client (even your internet browser can serve) on machine B to connect to machine A i.e. your server using the socket address 172.200.42.1:7000 [1].
[1] We will use this socket address because the application is running on machine A which is at IP address 172.200.42.1 on the network and the application is running on port 7000.
What I have done:
ALLOWED_HOSTS = ["*"]- runserver
- Important: add inbound rule at firewall, allow the connection applies to domain,private,public, TCP ThePort