How can this be used with `django.setup()`
Opened this issue · 2 comments
spookylukey commented
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
I found the answer, you have to do configurations.setup()
. It would be nice if this was documented, thanks!
elton2048 commented
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.