This is the directory structure of my Django project. When I am running python code of importing a model:from scraping.models import LinkVendorStandard
from the file "framework_product_processing.py" it throws this exception:
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
When I add this code:
import django
django.setup()
to initialize the django project settings, I get this exception: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I have the following 2 questions about this behavior:
- The file:"framework_product_process.py" in the django project structure is at the same level as "views.py" which can access model without having to setup the Django project.If this file is accessible from the same python path as that of view then why django.core.exceptions.ImproperlyConfigured?
- Even after adding
import django;django.setup()
code why I get django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.?
Can anyone please explain?
Update:
The file "framework_prodcut_processing.py" runs without any errors when I move it to a non_app python directory. non_app is not a Django app.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…