我正在尝试在我的服务器上为 python 设置中间件,以便服务器上的 apache2 可以看到蓝图的子目录,并在example.com/myapplicationsubfolder/routedblueprintfunction之类的 URL 下提供服务
我/users/ 文件夹中的__init__.py如下所示:
class WebFactionMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
environ['SCRIPT_NAME'] = '/myapplicationsubfolder'
return self.app(environ, start_response)
from index import application
application.wsgi_app = WebFactionMiddleware(application.wsgi_app)
在我制作了我的应用程序工厂后,我不能再使用它了:
from app import app
app.wsgi_app = WebFactionMiddleware(app.wsgi_app)
我正在尝试从 index.py 获取烧瓶应用程序
Index.py是这样的:
from app import create_app
application = create_app()
application.run()
app.py像这样:
def configure_errors(app):
@app.errorhandler(500)
def internal_server_error(error):
return render_template('500.html'), 500
def create_app():
app = Flask(__name__)
app.config.from_object('config')
from users.views import b_users
db.init_app(app)
app.register_blueprint(b_users)
configure_errors(app)
return app
如果有人有一个大型蓝图应用程序实现源代码的链接,该源代码使用 WSGI 中间件作为 python Flask 网站的子目录,那将有很大帮助。
我遇到了一些严重的循环导入问题或子目录 init.py 问题。
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] File "/home/somefolder/webapps/applicationsubfolder/htdocs/index.py", line 8, in <module>
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] from app import create_app
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] File "/home/somefolder/webapps/applicationsubfolder/htdocs/app.py", line 5, in <module>
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] from users.views import b_users
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] File "/home/somefolder/webapps/applicationsubfolder/htdocs/users/__init__.py", line 9, in <module>
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] from index import application
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] File "/home/somefolder/webapps/applicationsubfolder/htdocs/index.py", line 8, in <module>
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] from app import create_app
[Sat Nov 24 05:32:59 2012] [error] [client 127.0.0.1] ImportError: cannot import name create_app