Skip to content

Script Refresh Allowed Hosts

Alexandar83 edited this page Feb 25, 2025 · 2 revisions

WSL2 assigns a dynamic IP to its virtual network adapter (eth0). This causes issues when trying to access services at http://localhost:8000/ running in WSL2 from the Windows host, as they aren't bound to localhost. Additionally, Django requires the server's IP to be listed in ALLOWED_HOSTS to respond to requests, rejecting others for security reasons. The script automates retrieving the current WSL2 IP and updating ALLOWED_HOSTS, ensuring seamless access to the application.

Script Breakdown

1. Configures the ALLOWED_HOSTS environment variable by:

  • Removing any outdated WSL2 IP addresses from the ALLOWED_HOSTS.
  • Adding the current WSL2 IP address to the ALLOWED_HOSTS.

2. The environment file in which the modifications are made is determined, based on the --deployment_mode (required) argument:

  • --deployment_mode=dev  ->  config/envs/dev/the_wall_api_dev.env
  • --deployment_mode=prod_v2  ->  config/envs/prod/the_wall_api_prod.env

3. Outputs the current WSL2 IP address in the console, helping the user determine where the application is accessible.


Scripts Index
Home Page


Clone this wiki locally