jazzband / django-configurations

A helper for organizing Django project settings by relying on well established programming patterns.
https://django-configurations.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.1k stars 143 forks source link

How can this be used with `django.setup()` #359

Open spookylukey opened 1 year ago

spookylukey commented 1 year ago

I have scripts that start like this:

import os
if not "DJANGO_SETTINGS_MODULE" in os.environ:
    raise AssertionError("You need DJANGO_SETTINGS_MODULE in your os.environ")

import django
django.setup()

When attempting to run this, I get:

django.core.exceptions.ImproperlyConfigured: django-configurations settings importer wasn't correctly installed. Please use one of the starter functions to install it as mentioned in the docs: https://django-configurations.readthedocs.io/

I couldn't find documentation for how to get this working with django-configurations. The docs talk about cases that use execute_from_command_line, but I don't want/need to use that here. Is there a way to get this to work?

Thanks!

spookylukey commented 1 year ago

I found the answer, you have to do configurations.setup(). It would be nice if this was documented, thanks!

elton2048 commented 1 year ago

I think the author writes this in https://django-configurations.readthedocs.io/en/latest/patterns.html#standalone-scripts, maybe the doc can add a common scenario which it replaces django.setup() for configurations to be activated.