Python

Requested setting INSTALLED_APPS, but settings are not configured. You must either define..

Requested setting INSTALLED_APPS, but settings are not configured. You must either define.., someone asked me to explain?
I got this following error while running the python outside of the usual manage.py commands.

CODE:

from app.models import Bank

banks_queryset = Bank.objects.all()

# Convert the queryset to a list
banks_list = list(banks_queryset)

print(banks_list[0])
SOLUTION:
If you are running the python outside of the usual manage.py. you need to configure the environment variable "DJANGO_SETTING_MODULE". you can set it in your script before accessing the model.

UPDATED CODE:

import os

import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE','quic_project.settings')
django.setup()

from app.models import Bank

banks_queryset = Bank.objects.all()

# Convert the queryset to a list
banks_list = list(banks_queryset)

print(banks_list[0])
VIDEO GUIDE:

Post your comments / questions