I can not run the project, I did what I was told in README.md as directed, but still gives an error.

The Output is:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\environ\environ.py", line 403, in get_value
    value = self.ENVIRON[var_name]
            ~~~~~~~~~~~~^^^^^^^^^^
  File "<frozen os>", line 678, in __getitem__
KeyError: 'SECRET_KEY'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\new-folder\manage.py", line 21, in <module>
    main()
  File "C:\new-folder\manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\base.py", line 93, in wrapped
    saved_locale = translation.get_language()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\utils\translation\__init__.py", line 210, in get_language
    return _trans.get_language()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\utils\translation\__init__.py", line 65, in __getattr__
    if settings.USE_I18N:
       ^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\conf\__init__.py", line 92, in __getattr__
    self._setup(name)
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\conf\__init__.py", line 79, in _setup
    self._wrapped = Settings(settings_module)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\conf\__init__.py", line 190, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\new-folder\usn_uchet\settings.py", line 26, in <module>
    SECRET_KEY = ENV.str('SECRET_KEY')
                 ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\environ\environ.py", line 213, in str
    value = self.get_value(var, cast=str, default=default)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\environ\environ.py", line 407, in get_value
    raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable

settings.py file

import os
import environ
from pathlib import Path
from django.utils.log import DEFAULT_LOGGING
import urllib3

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

ENV = environ.Env(DEBUG=(bool, True))


ENV_FILE = Path(os.path.join(BASE_DIR, '.env'))
if ENV_FILE.exists():
    environ.Env.read_env(os.path.join(BASE_DIR, '.env'))

DEBUG = ENV.bool('DEBUG', True)
LOGLEVEL = ENV.str('LOGLEVEL', 'INFO')
SECRET_KEY = ENV.str('SECRET_KEY')
CRYPTO_KEY = bytes(ENV.str('CRYPTO_KEY'), 'UTF-8')
ALLOWED_HOSTS = ENV.list('ALLOWED_HOSTS', default=[])

.env file

DEBUG=on
SECRET_KEY=My_key

and how do I fix this error to start the server ? what to do to get rid of this error tried to remove the space, also added to the directory where the settings.py.what you said in the previous question doesn't work

0

There are 0 answers