Based on other posts, I've added a new .env file within my app but this error is still appearing. I've also added the top setting module in my settings.py file but still no luck. Any thoughts on what's causing this?
Path to project (where db and manage.py exist): C:\Users\xxx\Python\Price Tracking\Django\mysite
Visual Studio Code Terminal Error:
Traceback (most recent call last):
File "c:/xxxx/Python/Price Tracking/Django/mysite/polls/models.py", line 7, in <module>
class Question(models.Model):
File "C:\Python38\lib\site-packages\django\db\models\base.py", line 107, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Python38\lib\site-packages\django\apps\registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "C:\Python38\lib\site-packages\django\apps\registry.py", line 134, in check_apps_ready
settings.INSTALLED_APPS
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 57, in _setup
raise ImproperlyConfigured(
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.
PS C:\Users\xxxx\Python\Price Tracking\Django\mysite>
error 2
Traceback (most recent call last):
File "c:/Users/xxx/Python/Price Tracking/Django/mysite/mysite/settings.py", line 19, in <module>
django.setup()
File "C:\Python38\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\xxxx\Python\Price Tracking\Django\mysite\mysite\settings.py", line 19, in <module>
django.setup()
File "C:\Python38\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python38\lib\site-packages\django\conf\__init__.py", line 161, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
settings
import os
import sys
sys.path.append(r"C:\Users\xxxx\Python\Price Tracking\Django\mysite")
os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
import django
django.setup()
from django.core.management import call_command
from pathlib import Path
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '**=6fb4%z!pxp*ce8$kvj+z2%98)jo&hv!*3*m^wxxxxxxxxxxxxxx'
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_plotly_dash.apps.DjangoPlotlyDashConfig',
'chartjs',
]
C:\Users\xxxx\Django\mysite.env file:
DJANGO_SETTINGS_MODULE='mysite.settings'