Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spookylukey opened this issue May 3, 2023 · 2 comments
Open

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

spookylukey opened this issue May 3, 2023 · 2 comments

Comments

@spookylukey
Copy link

spookylukey commented May 3, 2023

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
Copy link
Author

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

@elton2048
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants