我在Ubuntu16.4上安装了apache2和wsgi 我收到了这个错误;
ImportError: No module named 'settings'
在我的Django项目文件夹中,有一个名为“settings”的目录,在“settings”文件夹中,存在多个设置文件,如default.py, development.py,...
。
在wsgi_dev.py
内,设置已完成wsgi。
os.environ.setdefault("DJANGO_SETTINGS_MODULE",'settings.development')
此设置文件夹无法识别为模块。我有__init__.py
内部设置文件夹。
`File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 22, in setup`
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 56, in getattr
self._setup(name)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 110, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in find_and_load`
File "<frozen importlib._bootstrap>", line 944, in find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
答案 0 :(得分:1)
在wsgi.py
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.development'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.development")
答案 1 :(得分:0)
通常,外部项目目录(包含manage.py
的目录)位于Python路径上,因此在设置DJANGO_SETTINGS_MODULE
时必须包含项目名称。例如:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'mysite.settings.development')