python - "Apps aren't loaded yet" and "django.core.exceptions.ImproperlyConfigured" in Django? -


enter image description here

this directory structure of django project. when running python code of importing model:from scraping.models import linkvendorstandard file "framework_product_processing.py" throws exception:

django.core.exceptions.improperlyconfigured: requested setting default_index_tablespace, settings not configured. must either define environment variable django_settings_module or call settings.configure() before accessing settings.

when add code: import django django.setup()

to initialize django project settings, exception: django.core.exceptions.appregistrynotready: apps aren't loaded yet.

i have following 2 questions behavior:

  1. the file:"framework_product_process.py" in django project structure @ same level "views.py" can access model without having setup django project.if file accessible same python path of view why django.core.exceptions.improperlyconfigured?
  2. even after adding import django;django.setup() code why django.core.exceptions.appregistrynotready: apps aren't loaded yet.?

can please explain?

update:enter image description here file "framework_prodcut_processing.py" runs without errors when move non_app python directory. non_app not django app.

django.core.exceptions.improperlyconfigured

when run commands python manage.py runserver, django automatically runs django.setup using django_settings_module environment variable. code in views.py can access models, because django ensures django.setup called before views imported. since running shell script simple python file, must manually call django.setup.

django.core.exceptions.appregistrynotready: apps aren't loaded yet

this happens when app gets imported before complete settings files imported (i.e. before initialization of installed_apps). make sure don't have code in settings file, imports code other apps.

also ensure not importing models or similar app code, in __init__.py files of apps.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -