【问题标题】:mod_python returns a blank screenmod_python 返回一个空白屏幕
【发布时间】:2017-08-06 13:26:58
【问题描述】:

我正在尝试在 apache2 中运行 mod_python.publisher。我想做的只是打印“Hello World”

当我运行我的程序时,我得到一个空白屏幕。 我的 .py 程序如下所示:

def index():
    print ("Hello World")
index() 

但是当我运行程序时:

def index(req):
    print ("Hello World")
index()

我收到这条错误消息,上面写着 index() 需要和参数,并且给出了 0:

MOD_PYTHON ERROR

ProcessId:      23348
Interpreter:    'test.com'

ServerName:     'test.com'
DocumentRoot:   '/var/www'

URI:            '/modPythonTest.py'
Location:       None
Directory:      '/var/www/'
Filename:       '/var/www/modPythonTest.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 "/var/www/modPythonTest.py", line 5, in <module>
    index()

    TypeError: index() takes exactly 1 argument (0 given)

因此,基于此,我看起来正在编译我的代码。我收到错误代码的错误,但没有输出好代码。有什么想法吗?

【问题讨论】:

  • 您将参数req 添加到索引函数中,但您对index() 的调用未提供参数,例如index(1)

标签: python apache2 mod-python


【解决方案1】:

这最终对我有用:

#!/usr/bin/python
from mod_python import apache

def index(req):
    out = "<html><head>"
    out = out+"<meta http-equiv='content-type' content='text/html'></head>"
    out = out+"<body>Hello World</body></html>"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 2021-11-09
    • 1970-01-01
    相关资源
    最近更新 更多