Хочу сделать свой маленький проект и решил подключить PSQL.
Решил, что лучше не хранить пароли и т.д в Settings, а импортировать с другого файла.
Вот если что моя структура файлов на данный момент:
Вот как сейчас всё выглядит в settings.py :
...
from my_first_site.my_first_site.local_settings import db
...
DATABASES = {
'default': db,
}
Вот файл local_settings.py:
db = {'ENGINE': 'django.db.backends.postgresql',
'NAME': 'poll_db',
'USER': 'app_manager',
'PASSWORD': 'TWENTY04',
'HOST': 'localhost',
'PORT': '5432', }
Когда проверяю базу данных командой, которую я нашел в документации django
py manage.py check --database default
я получаю ошибку:
Traceback (most recent call last):
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\base.py", line 460, in execute
output = self.handle(*args, **options)
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\commands\check.py", line 76, in handle
self.check(
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\base.py", line 487, in check
all_issues = checks.run_checks(
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\checks\translation.py", line 32, in check_setting_language_code
tag = settings.LANGUAGE_CODE
File "C:\Projects\Django-project\venv\lib\site-packages\django\conf\__init__.py", line 87, in __getattr__
self._setup(name)
File "C:\Projects\Django-project\venv\lib\site-packages\django\conf\__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "C:\Projects\Django-project\venv\lib\site-packages\django\conf\__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\GHOST\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Projects\Django-project\my_first_site\my_first_site\settings.py", line 12, in <module>
from my_first_site.my_first_site.local_settings import db
ModuleNotFoundError: No module named 'my_first_site.my_first_site'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Projects\Django-project\my_first_site\manage.py", line 22, in <module>
main()
File "C:\Projects\Django-project\my_first_site\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Projects\Django-project\venv\lib\site-packages\django\core\management\base.py", line 427, in run_from_argv
connections.close_all()
File "C:\Projects\Django-project\venv\lib\site-packages\django\db\utils.py", line 212, in close_all
for alias in self:
File "C:\Projects\Django-project\venv\lib\site-packages\django\utils\connection.py", line 73, in __iter__
return iter(self.settings)
File "C:\Projects\Django-project\venv\lib\site-packages\django\utils\functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Projects\Django-project\venv\lib\site-packages\django\utils\connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "C:\Projects\Django-project\venv\lib\site-packages\django\db\utils.py", line 148, in configure_settings
databases = super().configure_settings(databases)
File "C:\Projects\Django-project\venv\lib\site-packages\django\utils\connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "C:\Projects\Django-project\venv\lib\site-packages\django\conf\__init__.py", line 87, in __getattr__
self._setup(name)
File "C:\Projects\Django-project\venv\lib\site-packages\django\conf\__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "C:\Projects\Django-project\venv\lib\site-packages\django\conf\__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\GHOST\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Projects\Django-project\my_first_site\my_first_site\settings.py", line 12, in <module>
from my_first_site.my_first_site.local_settings import db
ModuleNotFoundError: No module named 'my_first_site.my_first_site'