mary
mary

Reputation: 11

Requested setting INSTALLED_APPS, but settings are not configured

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

i'm trying to fetch data from a model and perform calculations on it and then uploading it into another model but it's showing me this error can anyone tell what to do.

from proto.department import DepartmentSummary


courseA = course.objects.values_list('No_Students', flat=True)
courseA = list(courseA)
department_name=['BSCS']
count = 0
total_students = 0
length = len(courseA)
i=0
while i<length:
    if courseA>0:
        count=count+1
    total_students = total_students+courseA

for name in department_name:
    lt, created = DepartmentSummary.objects.get_or_create(
        Department_Name=name,
    )
    if not created:
        lt.Active_courses = count
        lt.Active_students = total_students
    lt.save() ```


Upvotes: 0

Views: 2117

Answers (1)

D. Anthropoid
D. Anthropoid

Reputation: 143

Try the following:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'proto.settings'

Perhaps will work for you? (I'm assuming "proto" is your project)

Upvotes: 1

Related Questions