扭曲应用程序的Web界面

我有一个用Twisted编写的应用程序,我想添加一个Web界面来控制和监视它。我需要大量的动态页面来显示当前的状态和配置,所以我希望一个框架至少提供一个带继承和一些基本路由的模板语言。 因为我正在使用Twisted,所以我想使用
twisted.web
- 但它的模板语言太基本了,似乎唯一的框架,Nevow已经死了(它在启动板上,但主页和wiki都关闭了,我找不到任何文档)。 那么我的选择是什么? 还有其他基于
twisted.web
的框架吗? 还有其他框架可以与扭曲的反应堆一起使用吗? 我应该只是获得一个Web框架(我在想web.py或flask)并在一个线程中运行它? 谢谢你的回答。     
已邀请:
由于Nevow仍在使用,我不想自己编写路由和支持模板库,我最终使用了Flask。结果很简单:
# make a Flask app
from flask import Flask, render_template, g
app = Flask(__name__)
@app.route("/")
def index():
    return render_template("index.html")

# run in under twisted through wsgi
from twisted.web.wsgi import WSGIResource
from twisted.web.server import Site

resource = WSGIResource(reactor, reactor.getThreadPool(), app)
site = Site(resource)

# bind it etc
# ...
到目前为止它完美无瑕。     
您可以将其直接绑定到反应器中,如下例所示:
reactor.listenTCP(5050, site)
reactor.run()
如果需要将子项添加到WSGI根目录,请访问此链接以获取更多详细信息。 这是一个示例,说明如何将WSGI资源与静态子组合。
from twisted.internet import reactor
from twisted.web import static as Static, server, twcgi, script, vhost
from twisted.web.resource import Resource
from twisted.web.wsgi import WSGIResource
from flask import Flask, g, request

class Root( Resource ):
    """Root resource that combines the two sites/entry points"""
    WSGI = WSGIResource(reactor, reactor.getThreadPool(), app)
    def getChild( self, child, request ):
        # request.isLeaf = True
        request.prepath.pop()
        request.postpath.insert(0,child)
        return self.WSGI
    def render( self, request ):
        """Delegate to the WSGI resource"""
        return self.WSGI.render( request )

def main():
static = Static.File("/path/folder")
static.processors = {'.py': script.PythonScript,
                 '.rpy': script.ResourceScript}
static.indexNames = ['index.rpy', 'index.html', 'index.htm']

root = Root()
root.putChild('static', static)

reactor.listenTCP(5050, server.Site(root))
reactor.run()
    
Nevow是显而易见的选择。不幸的是,divmod Web服务器硬件和备份服务器硬件同时出现故障。他们正试图恢复数据并将其发布在启动板上,但可能需要一段时间。 你也可以使用twisted.web基本上任何现有的模板模块; Jinja2浮现在脑海中。     

要回复问题请先登录注册