使用mod_wsgi导入python模块

Jua*_*oto 3 python apache mod-wsgi

我们正试图让wsgi应用程序在mod_wsgi上运行.我们在使用之前运行它wsgiref.simple_server,作为调试环境.现在,我们希望将其转移到使用Apache httpd与在同一端口下加载静态文件集成,并提供更适合生产的环境.

我们设置的httpd.conf文件如下所示:

<VirtualHost *:80>

    DocumentRoot /var/www/

    ErrorLog /var/www/log/error_log

    LogLevel debug

    WSGIScriptAlias /app /var/www/python/resource/rest.py

    <Directory /var/www/python/>
            Order allow,deny
            Allow from all
    </Directory>

    <Directory />
            Order allow,deny
            Allow from all

            RewriteEngine On
            # Some rewrites go here

    </Directory>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

通过这种设置,我们可以访问主应用程序文件rest.py(下http://myhost/app),但是对模块的任何导入(比如from module1 import functionmodule1与rest.py位于同一目录下)都会失败ImportError.

我怀疑这与必须设置某种环境变量有关,但我已添加/var/www/pythonsys.path主应用程序方法,但它不起作用.任何帮助或指向这一点将非常感激.

谢谢!

ran*_*man 6

在/ var/www/python或/ var/www/python/resource下是rest.py吗?据我所知,将此目录添加到sys.path应该可以正常工作.优先使用字符串常量如下:

sys.path.append(os.path.dirname(__file__))
Run Code Online (Sandbox Code Playgroud)

即使您决定将来部署到其他位置,这也应该有效.