这是我的项目结构:
Project
|_Application_one
|_Application_two
|_DjangoProject (Now has been deleted)
|_manage.py
|_settings.py
|_urls.py
|_templates
|_home.html
我想在有人放置地址home.html
时加载127.0.0.1:8000\home.html
的内容,但每当我运行Django
服务器时,它都会抛出以下错误:
ImportError: Could not import settings 'DjangoProject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named DjangoProject.settings
代码manage.py
import os
import sys
try:
import settings
except ImportError:
import sys
sys.stderr.write("Error: Can't Find the files settings.py in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
if __name__== "__main__":
import settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我想加载settings.py(外部),但它要求DjangoProject.settings.py。我该如何访问settings.py?
修改
wsgi.py文件
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
回溯
Traceback (most recent call last):
File "C:/Users/test/Desktop/project/manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_command
commands = get_commands()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'DjangoProject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named DjangoProject.settings