Answer the question
In order to leave comments, you need to log in
How to import Django settings from a standalone script?
I am writing a script separately from Dzhangi, I don’t want to import too much into it. Only the Django settings from settings_local are needed.
The structure is:
apps
- __init__.py
- settings_local.py
standalone
- __init__.py
- syncraw.py
In syncraw.py I tried different options from the following:
from .settings_local import DATABASES
from ..settings_local import DATABASES
Answer the question
In order to leave comments, you need to log in
A working (but incorrect) answer is to add the directory that contains both apps and standalone to PYTHONPATH.
This is done in two ways: either through the PYTHONPATH environment variable when launched from the console:
or by adding the directory directly in the script:
# syncraw.py
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from apps.settings_local import *
print(DEBUG)
If the script is associated with a Django project, it is correct to do the managment command - https://docs.djangoproject.com/en/1.10/howto/custo...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question