0

我正在关注一个关于在 WampServer 上设置 mod_wsgi的简单教程,在我尝试Import之前,一切都运行良好,我尝试搜索网络,但没有得到有效的解决方案,这是一个错误问题(可能不是)或者肯定是配置问题?

如何在 mod_wsgi 中导入模块?

设置: windows8 64 / wampserver x64 bit / mod_wsgi x64bit

目录:

  1. Wampserver: c:/wamp
  2. wsgi 应用程序:c:/wamp/www/wsgi
  3. Python27 : c:/python27

wsgi 应用程序的别名:{按照教程中通过 wamp 的创建别名选项创建}

WSGIScriptAlias /wsgi/ "c:/wamp/www/wsgi/wsgi.py"
<Directory "c:/wamp/www/wsgi/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>

wsgi.py

from paste import httpserver

try :
    p = sys.argv[1]
    command = "from %(project)s import *" % {"project": p}
    exec(command)
    httpserver.serve(app, host='127.0.0.1', port='8080')

except :
    print "Usage: python runner.py <main_package>"
    sys.exit(0)

apache-错误日志:

  • 目标 WSGI 脚本“C:/wamp/www/wsgi/wsgi.py”不能作为 Python 模块加载。
  • 处理 WSGI 脚本“C:/wamp/www/wsgi/wsgi.py”时发生异常。
  • 从粘贴导入 httpserver ImportError:无法导入名称 httpserver

但是,如果我将上面的代码更改为:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'
    response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

它打印输出。

尝试 wsgi.py 的选项:

import os, sys
sys.path.append("c:\\wamp\\www\\wsgi\\paste\\")
sys.path.append(os.path.dirname(__file__))
sys.path.append('c:/wamp/www/wsgi/')
sys.path.insert(0, 'c:/wamp/www/wsgi')
sys.path.insert(1, 'c:/wamp/www')
sys.path.insert(0, "c:/wamp/www/wsgi/wsgi.py")
sys.path.insert(0, "c:/wamp/www/wsgi/paste")

编辑:粘贴模块位于应用程序根目录中。

4

2 回答 2

0

您没有提到您已将 Python 激活为 Apache 中的有效 CGI。

这有帮助吗 ->配置 Apache 以使用 Python

于 2013-10-21T10:10:48.290 回答
0

尝试删除最后的斜线:

  WSGIScriptAlias /wsgi "c:/wamp/www/wsgi/wsgi.py"

代替:

  WSGIScriptAlias /wsgi/ "c:/wamp/www/wsgi/wsgi.py"
于 2014-03-12T17:38:23.103 回答