Sample Header Ad - 728x90

How to export a list of IP addresses as a single local variable?

0 votes
1 answer
935 views
In Django, one has to specify the environment variable ALLOWED_HOSTS to define a list of server's IP addresses that are allowed to host a Django website. For example: ALLOWED_HOSTS=['localhost', '127.0.0.1', '1.2.3.4'], which means that if I'm logged locally on my webserver, then I can access the Django website locally. But globally, one can also access the server at 1.2.3.4. Developers frequently specify this environment variable in an environment file, such as .env, which is then parsed by Django. In my case, I have to set this environment variable on the Ubuntu Linux server, such as, say, locally; it would look like this: export ALLOWED_HOSTS=['localhost', '127.0.0.1', '1.2.3.4'] Now, this command doesn't work. Neither does work the command export ALLOWED_HOSTS="['localhost', '127.0.0.1', '1.2.3.4']" or export ALLOWED_HOSTS='localhost', '127.0.0.1', '1.2.3.4' or export ALLOWED_HOSTS="[localhost, 127.0.0.1, '1.2.3.4]" In the first and the third cases, one will get an error from bash due to incorrect syntax. In the 2nd and 4th cases, Django will simply not understand the variable. Yes, it is possible to pass the command export ALLOWED_HOSTS='localhost' which will be understood by Django, but this assumes only one allowed IP address. But I'm strongly convinced that it must be possible to somehow pass a list of IP addresses as a Linux environment variable, which will be understood by Django. But how?
Asked by sequence (321 rep)
Feb 9, 2022, 04:41 PM
Last activity: Mar 27, 2022, 12:56 PM