I am trying to query data from database using Python shell. settings.py
includes:
import django
django.setup()
...
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'products.apps.ProductsConfig',
'users.apps.UsersConfig',
'crispy_forms',
]
When i open Python shell i do:
> from django.conf import settings
> settings.configure()
Then I try to import models:
> from products.models import Product
However, Python returns:
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I tried adding django.setup()
call in settings and also moving this statement after INSTALLED_APPS
.
EDIT: With django.setup()
I get the following error when I try to run command runserver
:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.