2

我在本地机器上使用 Django 站点和 Ubuntu,刚刚上传但收到 500 内部服务器错误,我无法理解原因。

似乎无法看到某些模块,可能是它没有查看我的设置文件?以下是此问题的错误日志,可能揭示了正在发生的事情:

    [Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10] mod_wsgi (pid=23248): Exception occurred processing WSGI script '/var/www/kaasib/pypr$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10] Traceback (most recent call last):
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 24$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     response = self.get_response(request)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 17$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 22$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return debug.technical_500_response(request, *exc_info)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 66, in te$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     html = reporter.get_traceback_html()
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 276, in g$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return t.render(c)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 140, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return self._render(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 134, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return self.nodelist.render(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 823, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     bit = self.render_node(node, context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return node.render(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 84, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     output = self.filter_expression.resolve(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 599, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     new_obj = func(obj, *arg_vals)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/defaultfilters.py", li$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return format(value, arg)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 310,$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return df.format(format_string)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 33, $
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     pieces.append(force_unicode(getattr(self, piece)()))
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 214,$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return self.format('D, j M Y H:i:s O')
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 33, $
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     pieces.append(force_unicode(getattr(self, piece)()))
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py", line 71, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     s = unicode(s)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 121,$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return func(*self.__args, **self.__kw)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py",$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return _trans.ugettext(message)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return do_translate(message, 'ugettext')
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     _default = translation(settings.LANGUAGE_CODE)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     default_translation = _fetch(settings.LANGUAGE_CODE)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     app = import_module(appname)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, i$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     __import__(name)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10] ImportError: No module named company

这是 httpd.conf 文件的内容:

WSGIPythonPath /var/www/kaasib/pyproject/kaasib/

<Directory /var/www/kaasib/pyproject/kaasib/kaasib/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

WSGISCRIPTAlis 行位于站点可用的 vhost 文件中。以下是 wsgi 文件的内容:

"""
WSGI config for kaasib project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

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

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
4

3 回答 3

1

查看您的 apache conf 文件和您的应用程序的 wsgi conf 文件会很有帮助。

正如您所建议的,您的公司模块似乎找不到。这可能是因为很多原因。我将首先检查您的 WSGIPythonPath 并确保它包含您的应用程序。

查看Django WSGI 部署指南了解更多详细信息。

于 2012-12-28T22:46:51.120 回答
1

在我看来,您的项目不在您的 pythonpath 中。尝试在 wsgi.py 顶部添加它,看看效果如何:

import os, sys

path = '/path-to/your/project-root/'
if path not in sys.path:
   sys.path.append(path)
于 2012-12-29T03:36:10.743 回答
0

您是否通过 pip 或其他方式在远程服务器上安装了模块?它根本找不到模块名称公司。此外,请确保在设置文件中安装的 INSTALLED_APPS 中包含“公司”模块。

于 2012-12-28T22:49:17.920 回答