Web interface for a twisted application

后端 未结 3 1236
广开言路
广开言路 2020-12-28 22:25

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 conf

3条回答
  •  [愿得一人]
    2020-12-28 23:09

    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.

提交回复
热议问题