question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problems with lists in .env

See original GitHub issue

I don’t know if I am using this wrong here, but if, it does not look straight forwarded to me. I have this in settings.py

env = environ.Env(
    ALLOWED_HOSTS=(list, ['127.0.0.1', 'localhost']),
)

and this in .env

ALLOWED_HOSTS=['127.0.0.1', 'localhost']

Which wont work, because env('ALLOWED_HOSTS') will return ["['127.0.0.1', 'localhost']"]. But it should be ['127.0.0.1', 'localhost'] of course. If I try to use it without the list parameter in .Env, I will get an not callable error.

How can I manage, to use a list in .env as well?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
sergeyklaycommented, Sep 4, 2021
# Comma-separated list
ALLOWED_HOSTS=.localhost,127.0.0.1,[::1]

# Comma-separated list
INTERNAL_IPS=.localhost,127.0.0.1,[::1]
from pathlib import Path
from environ import environ


env = environ.Env(
    ALLOWED_HOSTS=(list, []),
    INTERNAL_IPS =(list, []),
)


BASE_DIR = Path(__file__).resolve().parent.parent
env.read_env(BASE_DIR / '.env')


ALLOWED_HOSTS = env('ALLOWED_HOSTS')
INTERNAL_IPS = env('INTERNAL_IPS')
1reaction
ptinkcommented, Feb 26, 2019

the syntax for lists in the .env file is comma separated values rather than python list syntax so it would be ALLOWED_HOSTS=127.0.0.1,localhost

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass a list as an environment variable? - Stack Overflow
1. The reason why I'd like to use env variables is because I can make a config file with stuff I'd use in...
Read more >
List of Environmental Issues Examples: 30 Biggest Threats
Climate change is a huge topic! Here's a list of 30 ENVIRONMENTAL issues examples to help us all understand what's CAUSING climate change....
Read more >
Problems with Environment Variables
This will print out all the currently set environment variables. Look in this list carefully. If the variable name is misspelt, then set...
Read more >
A list of 20 Environmental Issues We Must Address
A list of 20 Environmental Issues We Must Address · 1. Carbon Pollution · 2. Rising Global Temperature · 3. Deforestation · 4....
Read more >
Environment Variables and Choices() function issue
List not found". When opened app in edit mode all of the fields that are using Choices() function are failing with that error,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found