0

I am looking for a way to read from a list of variables and set them in Django settings using the settings.configure() method:

from django.conf import settings


def func(i):
    # do something and return

for item in items:
    settings.configure(item=func(item))

But have no idea how I could write this properly to get past the

TypeError: Setting 'item' must be uppercase.
  • Which settings are you trying to configure? As the error tells you, you can't use `item` as a setting name. At minimum, you'd need to call it `ITEM`. Per the docs page you linked _"Setting names **must** be all uppercase"_ – Brian61354270 Feb 10 '23 at 20:23
  • `**{item: func(item)}` – deceze Feb 10 '23 at 20:44
  • Note it’s an error to call `configure()` more than once, or to call `configure()` after any setting has been accessed. So you have to use exactly one of either `configure()` or `DJANGO_SETTINGS_MODULE`. Not both, and not neither. Refer to Django settings documentation for more on this. If you want to use the approach you wrote, add all items to a temp dict first and then pass it to `configure()` outside the loop. – Manny Feb 10 '23 at 21:40

0 Answers0