0

I have created a blog with django by following some book. The django website works but the terminal keeps on showing this message if i try to interpret the code on spyder(setting.py, models.py)

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.

Here ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings the solution which was given for this was: set DJANGO_SETTINGS_MODULE=mysite.settings as in the documentation for django. However if i stop the server and restart it after running the code i am still getting the same error. Could you please advise what setting it is referring to which are not configured?

This is perticularly odd because it prints out the same error message if I run this help(models.DateTimeField)

-Edit-

manage.py looks like this:

import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

Picture of dir: enter image description here

Slartibartfast
  • 600
  • 1
  • 13
  • 43
  • Normally you can find this line in the manage.py file when the project is generated. Can you check if that is right? – DrummerMann Jan 06 '22 at 21:55
  • @DrummerMann Not sure what you are referring to. I have posted my manage.py file in the question. Please advise – Slartibartfast Jan 06 '22 at 22:01
  • Is your directory like this (in the same directory as manage.py, is the directory 'mysite' and in it the settings.py file)? . ├── ... ├── mysite │ ├── settings.py └── manage.py – DrummerMann Jan 06 '22 at 22:03
  • @DrummerMann Yes, i have also added a picture of the dir in question. – Slartibartfast Jan 06 '22 at 22:11
  • If you run it using `python manaage.py runserver` then I don't really see what is wrong.. – DrummerMann Jan 06 '22 at 22:21
  • Just dont understand what that error is. Plus if later on if my website get complex i would have issue debugging it since it does not interpret the code, all i can do i save it – Slartibartfast Jan 06 '22 at 22:24

0 Answers0