扭曲的应用程序的Web界面 [英] Web interface for a twisted application

查看:99
本文介绍了扭曲的应用程序的Web界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Twisted编写的应用程序,我想添加一个Web界面来控制和监视它.我将需要大量动态页面来显示当前状态和配置,因此我希望有一个至少提供具有继承性和一些基本路由的模板语言的框架.

I have a application written in Twisted and I want to add a web interface to control and monitor it. I'll need plenty of dynamic pages that show the current status and configuration, so I hoped for a framework that offers at least a templating language with inheritance and some basic routing.

因为无论如何我都在使用Twisted,所以我想使用twisted.web-但模板语言太基础了,似乎唯一的框架Nevow已经死了(它是

Since I am using Twisted anyways I wanted to use twisted.web - but it's templating language is too basic and it seems that the only framework, Nevow is quite dead (it's on launchpad but the homepage and wiki are down and I can't find any documentation).

那我有什么选择?

  • 还有其他基于twisted.web的框架吗?
  • 还有其他适用于扭曲反应堆的框架吗?
  • 我是否应该获取一个Web框架(我正在考虑使用web.py或flask)并在线程中运行它?
  • Is there any other twisted.web based framework?
  • Are there other frameworks that work with twisted's reactor?
  • Should I just get a web framework (I'm thinking web.py or flask) and run it in a thread?

感谢您的回答.

推荐答案

由于Nevow仍然不可用,而且我不想自己编写路由和对模板库的支持,因此我最终使用了Flask.事实证明这很容易:

Since Nevow is still down and I didn't want to write routing and support for a templating lib myself, I ended up using Flask. It turned out to be quite easy:

# 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
# ...

到目前为止,它可以正常工作.

It works flawlessly so far.

这篇关于扭曲的应用程序的Web界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆