0

但是,在配置 mod_python/apache 或 wsgi/apache 时,我是新手。

我已经能够使用 python 调试器工具..pdb.set_trace()成功,特别是在使用 django 开发服务器时,即它向终端输出所有服务器活动,包括 pdb 接口。

那么,当尝试在 webfaction 等主机上部署 django 网站时,如何做这样的事情呢?

除了 ftp 进入 error_log 并阅读有关它的故障后,是否能够与系统交互,因为它正在发生?

希望我在这里足够清楚。

顺便说一句,以下是我要配置的文件。

import os
import sys

from os.path import abspath, dirname, join
from site import addsitedir

from django.core.handlers.modpython import ModPythonHandler

import pdb

class PinaxModPythonHandler(ModPythonHandler):
    def __call__(self, req):
        # mod_python fakes the environ, and thus doesn't process SetEnv. 
        # This fixes that. Django will call this again since there is no way
        # of overriding __call__ to just process the request.
        os.environ.update(req.subprocess_env)
        from django.conf import settings

        sys.path.insert(0, abspath(join(dirname(__file__), "../../")))

        sys.path.insert(0, os.path.join(settings.PINAX_ROOT, "apps/external_apps"))
        sys.path.insert(0, os.path.join(settings.PINAX_ROOT, "apps/local_apps"))

        sys.path.insert(0, join(settings.PINAX_ROOT, "apps"))
        sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))
        pdb.set_trace()

        return super(PinaxModPythonHandler, self).__call__(req)

def handler(req):
    # mod_python hooks into this function.
    return PinaxModPythonHandler()(req)

这是通过http产生的错误页面:

MOD_PYTHON ERROR

ProcessId:      318
Interpreter:    'web25.webfaction.com'

ServerName:     'web25.webfaction.com'
DocumentRoot:   '/etc/httpd/htdocs'

URI:            '/'
Location:       '/'
Directory:      None
Filename:       '/etc/httpd/htdocs'
PathInfo:       '/'

Phase:          'PythonHandler'
Handler:        'bc.deploy.modpython'

Traceback (most recent call last):

  File "/home/dalidada/webapps/birthconfidence/lib/python2.5/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/home/dalidada/webapps/birthconfidence/lib/python2.5/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/home/dalidada/webapps/birthconfidence/lib/python2.5/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/home/dalidada/webapps/birthconfidence/bc/deploy/modpython.py", line 33, in handler
    return PinaxModPythonHandler()(req)

  File "/home/dalidada/webapps/birthconfidence/bc/deploy/modpython.py", line 29, in __call__
    return super(PinaxModPythonHandler, self).__call__(req)

  File "/home/dalidada/webapps/birthconfidence/lib/python2.5/django/core/handlers/modpython.py", line 191, in __call__
    self.load_middleware()

  File "/home/dalidada/webapps/birthconfidence/lib/python2.5/django/core/handlers/base.py", line 40, in load_middleware
    raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)

ImproperlyConfigured: Error importing middleware django_openid.consumer: "No module named django_openid.consumer"
4

1 回答 1

1

mod_wsgi 站点上记录了如何将 pdb 与 mod_wsgi 一起使用。看:

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Python_Interactive_Debugger

其他调试技术显示在同一页面上。

于 2009-03-15T01:46:27.440 回答