Django —> python manage.py сервер запуска

#python #django

#python #django

Вопрос:

У меня был предыдущий проект django с именем ‘bike_project’. И у меня было два модуля настроек для разработки и производства внутри папки настроек bike_project.Во время этого проекта у меня было set DJANGO_SETTINGS_MODULE = bike_project.settings.development в командной строке.

Но теперь, когда я создаю новый проект django (seller bike), проект создается. Но когда я запускаю python manage.py «команда», я получаю следующую ошибку.

 D:seller_bike>python manage.py runserver
Traceback (most recent call last):
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementbase.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementcommandsrunserver.py", line 60, in execute
    super().execute(*args, **options)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementbase.py", line 369, in execute
    output = self.handle(*args, **options)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementcommandsrunserver.py", line 67, in handle
    if not settings.DEBUG and not settings.ALLOWED_HOSTS:
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoconf__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoconf__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoconf__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libimportlib__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 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bike_project'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagement__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagement__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementbase.py", line 341, in run_from_argv
    connections.close_all()
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbutils.py", line 225, in close_all
    for alias in self:
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbutils.py", line 219, in __iter__
    return iter(self.databases)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoutilsfunctional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangodbutils.py", line 153, in databases
    self._databases = settings.DATABASES
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoconf__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoconf__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoconf__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:UsersofficAppDataLocalProgramsPythonPython38-32libimportlib__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 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bike_project'
  

Комментарии:

1. У вас все еще есть проект bike_project ? Вы работаете в виртуальной среде? Вы использовали set DJANGO_SETTINGS_MODULE = bike_project.settings.development команду только в cmd перед запуском сервера или вы установили ее в виртуальной среде?

2. У меня есть bike_project. И я запускаю проекты django в виртуальной среде.

3. Как насчет set DJANGO_SETTINGS_MODULE = bike_project.settings.development ? Вы установили его только в cmd или в venv?

4. также я установил DJANGO_SETTINGS_MODULE = bike_project.settings.development только в cmd перед запуском сервера

5. Хорошо, закройте cmd. И попробуйте запустить сервер еще раз.