2

在 WSGI 文件中,我们将导入一个 py 文件为

from <pyFile> import app as application

但是是否可以通过执行以下操作将多个 py 文件加载到单个 wsgi 文件中:

from <pyFile1> import app1 as application
from <pyFile2> import app2 as application

我已经尝试了上述方法,但它不起作用。

有没有不同的方法来实现这一目标?

4

2 回答 2

2

如果uwsgi是您选择的实现,请考虑以下事项:

import uwsgi

from <pyFile1> import app1 as application1
from <pyFile2> import app2 as application2

uwsgi.applications = {'':application1, '/app2':application2}
于 2012-06-03T15:44:20.330 回答
0

You can't import various modules as the same name, e.g.

from moduleX import somevar as X
from moduleY import othervar as X

Results in X == othervar.

But anyway you can't have multiple applications running in the same instance of Python. That's because

The application object is simply a callable object that accepts two arguments [PEP 333].

Now, a simple WSGI application is something like:

def simple_app(environ, start_response):
    """Simplest possible application object"""
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ['Hello world!\n']

As you can see, there is no place here to make multiple applications working at the same time, due to the fact that every request is passed to ONE particular application callback.

于 2012-06-03T10:38:52.683 回答