简体   繁体   English

使用mod_wsgi导入模块

[英]Import modules with mod_wsgi

I'm following a simple tutorial on Setting up mod_wsgi on WampServer all runs fine until I try to Import , I tried searching the net, but didn't get a working solution, is this a bug issues (maybe not) or certainly a configuration issue? 我正在遵循有关在WampServer设置mod_wsgi的简单教程,在我尝试导入之前一切运行良好,我尝试搜索网络,但没有找到有效的解决方案,这是错误问题(也许不是)或肯定是配置问题?

How to Import a module in mod_wsgi? 如何在mod_wsgi中导入模块?

setup: windows8 64 / wampserver x64 bit / mod_wsgi x64bit 设置: Windows8 64 / wampserver x64位/ mod_wsgi x64位

Directory: 目录:

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

Alias for wsgi app: {created as per in the tutorial via wamp's create an alias option} 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 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-error-log: apache-error-log:

  • Target WSGI script 'C:/wamp/www/wsgi/wsgi.py' cannot be loaded as Python module. 目标WSGI脚本'C:/wamp/www/wsgi/wsgi.py'无法作为Python模块加载。
  • Exception occurred processing WSGI script 'C:/wamp/www/wsgi/wsgi.py'. 处理WSGI脚本'C:/wamp/www/wsgi/wsgi.py'时发生异常。
  • from paste import httpserver ImportError: cannot import name httpserver 从粘贴导入httpserver ImportError:无法导入名称httpserver

However if I change the above code to: 但是,如果我将上面的代码更改为:

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]

It prints output. 打印输出。

options tried wsgi.py: 选项尝试过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")

Edit: paste module is in apps root directory. 编辑:粘贴模块在应用程序的根目录中。

You dont mention that you have activated Python as a valid CGI in Apache. 您没有提到您已将Python激活为Apache中的有效CGI。

Does this help -> Configure Apache to use Python 这是否有帮助-> 配置Apache以使用Python

Try to delete the final slash: 尝试删除最后的斜杠:

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

instead of: 代替:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM