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:
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.
django.core.exceptions.ImproperlyConfigured
When you run commands like python manage.py runserver
, django automatically runs django.setup
for you using DJANGO_SETTINGS_MODULE
environment variable. So the code in views.py
can access models, because django ensures that django.setup
is called before views are imported. Since you are running your shell script as a simple python file, so you must manually call django.setup
.
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet
This generally happens when your app gets imported before the complete settings files are imported (i.e. before the initialization of INSTALLED_APPS). So make sure you don't have any code in settings file, which imports code from some other apps.
Also ensure that you are not importing models or similar app code, in __init__.py
files of your apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With