'django.core.exceptions.ImprperlyConfigured solution

I wonder why I get this error :

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.

this is my code :

from main_app.models import student

std1 = student(name='tom', fullname='scholz')
std1.save()

print(student.objects.all())

there is not any problem with running server and migrations. but when it comes to running a .py file (made by myself) such an error rises.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source