To configure ALLOWED_HOSTS
correctly, you should include the following:
- The local IP address (
192.168.0.18
). localhost
and127.0.0.1
for local development.- The hostname if you plan to access the server using a hostname.
- Optionally,
0.0.0.0
to allow all hosts (use with caution in development).
Here is an example of a comprehensive ALLOWED_HOSTS
configuration for development:
settings.py:
ALLOWED_HOSTS = [
'192.168.0.18', # Local network IP
'localhost', # Localhost access
'127.0.0.1', # Loopback address
'0.0.0.0', # Allows access from any host (useful for development, but use with caution)
]
Ensure you run the server with the command:
python3 manage.py runserver 0.0.0.0:8000
With the above configuration, you should be able to access the Django application using any of the following URLs:
-
From the same machine:
http://localhost:8000
http://127.0.0.1:8000
-
From other devices on the same local network:
http://192.168.0.18:8000
-
Optionally, if you have configured a hostname or a domain name, ensure it resolves to the correct IP address and add it to
ALLOWED_HOSTS
.
Assuming your local network IP is 192.168.0.18
and you want to access the Django server from another device on the same network, you can:
-
Run the server with:
python3 manage.py runserver 0.0.0.0:8000
-
Open a web browser on another device and navigate to:
http://192.168.0.18:8000
By following these steps, you should be able to access your Django application from different hosts in your development environment.