ImportError:没有名为appName.settings django 1.8 + Apache + mod_wsgi的模块

时间:2016-01-10 08:23:03

标签: python django apache

我知道已经发布了几个类似的问题,但他们的解决方案都不适合我。 你能帮忙弄清楚如何解决这个问题吗? 任何帮助表示赞赏。

版本信息:

apache2 2.4.7
os Ubuntu 14.04
django 1.8

错误消息

MOD_PYTHON ERROR

ProcessId:      15796
Interpreter:    '127.0.1.1'

ServerName:     '127.0.1.1'
DocumentRoot:   '/var/www/html'

URI:            '/'
Location:       None
Directory:      None
Filename:       '/home/stevenhe/mywork/src/listbaby/listbaby/wsgi.py'
PathInfo:       '/'

Phase:          'PythonHandler'
Handler:        'mod_python.publisher'

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/usr/lib/python2.7/dist-packages/mod_python/publisher.py", line 204, in handler
    module = page_cache[req]

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1059, in __getitem__
    return import_module(req.filename)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 296, in import_module
    log, import_path)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 680, in import_module
    execfile(file, module.__dict__)

  File "/home/stevenhe/mywork/src/listbaby/listbaby/wsgi.py", line 18, in <module>
    application = get_wsgi_application()

  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()

  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)

  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)

  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)

  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)

  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

ImportError: No module named listbaby.settings

我的项目结构

  • 项目路径:/home/stevenhe/mywork/src/listbaby

  • 应用名称:listbaby

  • 获取wsgi.py = /home/stevenhe/mywork/src/listbaby/lisbaby/wsgi.py

  • 的路径
  • 来自settings.py = /home/stevenhe/mywork/src/listbaby/lisbaby/settings.py

  • 的abs路径

wsgi.py的内容

import os, sys

from django.core.wsgi import get_wsgi_application
#sys.path.append('/home/stevenhe/mywork/src/listbaby') if I add this line, http simply returns 404 error
sys.path.append('/home/stevenhe/mywork/src/listbaby/listbaby')

os.environ["DJANGO_SETTINGS_MODULE"]="listbaby.settings"

application = get_wsgi_application()

apache2.conf的内容

   WSGIScriptAlias / /home/stevenhe/mywork/src/listbaby/listbaby/wsgi.py
   WSGIPythonPath /home/stevenhe/mywork/src/listbaby

<Directory /home/stevenhe/mywork/src/listbaby/listbaby>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

2 个答案:

答案 0 :(得分:0)

您错过了INSTALLED_APPS中列出的要安装的软件包。这是一个回归 - 如果你升级到最新的Django 1.8.x,它会告诉你丢失的应用程序。通过pip安装它你应该很好。

答案 1 :(得分:0)

确保项目中的manage.py文件已将os.environ设置为listbaby.settings。

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "listbaby.settings")