无法配置带有多个应用的Django项目

2024-04-25 06:24:32 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我的项目结构:

Project
    |_Application_one
    |_Application_two
    |_DjangoProject (Now has been deleted)
    |_manage.py
    |_settings.py
    |_urls.py
    |_templates
           |_home.html  

当有人输入地址127.0.0.1:8000\home.html时,我想加载home.html的内容,但每当我运行Django服务器时,它就会抛出以下错误:

^{pr2}$

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)

我要装货设置.py(外一个)但它要求djangproject.settings.py. 我该如何访问设置.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

Tags: djangoinfrompycoreimportsettingsinit