簡體   English   中英

mod_python返回黑屏

[英]mod_python returns a blank screen

我正在嘗試在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)

因此,基於此,我似乎正在編譯我的代碼。 我從錯誤的代碼中得到了一個錯誤,但是在良好的代碼上沒有輸出。 有任何想法嗎?

最終為我工作:

#!/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>"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM