django-admin“ModuleNotFoundError:”在更改开发和 生产环境 的设置结构后

loading...


0

Background

我最近开始学习Python Django . 我读到,为不同的环境提供单独的设置文件是一种很好的做法 . 因此,我试图实现类似于本维基"Simple Package Organization for Environments"部分中描述的内容:https://code.djangoproject.com/wiki/SplitSettings

Problem

当我现在运行django-admin命令时,我得到一个ModuleNotFoundError . 下面我复制粘贴了我为“django-admin check --deploy”获取的错误日志 . “python manage.py runserver --settings = CollegeComp.settings.development”工作正常 .

Things I've tried

我读到我可能要在我的虚拟环境中重置DJANGO_SETTINGS_MODULE环境变量 . 我输入“设置DJANGO_SETTINGS_MODULE = CollegeComp.settings.development”,但我仍然得到同样的错误 .

Python path

当我在激活我的虚拟环境的shell中键入以下内容时:

import sys
print(sys.path)

我得到以下内容:

['C:\\Users\\myusername\\Documents\\UdemyDjango\\MyPersonalProject\\College-Project-master\\CollegeComp', 
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\python37.zip', 
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\DLLs',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\lib',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\lib\\site-packages']

Error log

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\Scripts\django-admin-script.py", line 10, in <module>
    sys.exit(execute_from_command_line())
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\management\base.py", line 329, in run_from_argv
    connections.close_all()
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\db\utils.py", line 220, in close_all
    for alias in self:
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\db\utils.py", line 214, in __iter__
    return iter(self.databases)
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\utils\functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\db\utils.py", line 147, in databases
    self._databases = settings.DATABASES
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\conf\__init__.py", line 57, in __getattr__
    self._setup(name)
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\conf\__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\conf\__init__.py", line 107, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'CollegeComp'

My project directory

CollegeComp
|-CollegeComp
  |-settings
    |-__init__.py
    |-base.py     
    |-development.py 
    |-local.py 
    |-production.py
  |-__init__.py 
  |-urls.py  
  |-wsgi.py
|-<my apps>

base.py

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR =  os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
<rest of standard Django settings.py code>

development.py

from CollegeComp.settings.base import *

#Override base.py settings here
DEBUG = True


#Import local setting file
try:
    from CollegeComp.settings.local import *
except:
    pass

local.py

from CollegeComp.settings.base import *

#Override base settings here

DEBUG = True

production.py

from CollegeComp.settings.base import *

#Override base settings here

DEBUG = False


#Import local setting file
try:
    from CollegeComp.settings.local import *
except:
    pass

System info

Django 2.1版操作系统:Windows 10 Python版本:3.7.0

我很感激能得到任何帮助 .

loading...

0回答

No Data

评论

暂时没有评论!