简体   繁体   English

复杂的Python Bottle应用程序+ WSGI

[英]Complex Python Bottle App + WSGI

I have a python bottle application inside of a single folder that's been organized by function and I would like to convert my existing cherrypy usage over to apache mod_wsgi. 我在按功能组织的单个文件夹中有一个python瓶应用程序,我想将现有的cherrypy用法转换为apache mod_wsgi。

The folder structure looks like the following: 文件夹结构如下所示:

- project
-- app.py (loads the webserver class and runs it)
-- app
--- common
--- logs
--- modules
--- tools
--- web
---- webserver.py

The reason for this structure was so code from common could be used within tools and web without any issue. 之所以采用这种结构,是因为通用代码可以在工具和网络中使用而不会出现任何问题。 Imports are all done in a style of "from app.common.blah import utility". 导入均以“来自app.common.blah导入实用程序”的样式完成。 When trying to setup mod_wsgi, it expects to load up a simple application. 尝试设置mod_wsgi时,它希望加载一个简单的应用程序。

Is it possible to run mod_wsgi with a folder structure like this? 是否可以使用这样的文件夹结构运行mod_wsgi? If not, are there any recommendations for setting up a structure that will allow for mod_wsgi, but also the sharing of common utilities between folders like tools and web? 如果不是,是否有任何建议来设置允许使用mod_wsgi的结构,以及在工具和Web等文件夹之间共享公用程序?

From the Bottle deployment docs on Deployment : Deployment上Bottle部署文档中

All you need is an app.wsgi file that provides an application object. 您需要的只是一个提供应用程序对象的app.wsgi文件。 This object is used by mod_wsgi to start your application and should be a WSGI-compatible Python callable. mod_wsgi使用此对象来启动您的应用程序,并且应该是可与WSGI兼容的Python调用对象。

File /var/www/yourapp/app.wsgi : 文件/var/www/yourapp/app.wsgi

import os
# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))

import bottle
# ... build or import your bottle application here ...
# Do NOT use bottle.run() with mod_wsgi
application = bottle.default_app()

In your case, edit the snippet above to import the application object that is presumably defined in your app.py 就您而言,请编辑上面的代码段以导入大概在您的app.py定义的应用程序对象

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

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