Python web服务的微型框架:Klein

jopen 10年前

Klein是一个使用Python来开发可用于生产环境web服务的微型框架。它基于使用非常广泛且经过良好测试的组件,比如Werkzeug和Twisted,以及近乎完全的测试覆盖率。
Klein is a micro-framework for developing production-ready web services with Python. It’s built on widely used and well tested components like Werkzeug and Twisted, and has near-complete test coverage.

Example – Serving Static Files

Helpfully you can also return a t.w.resource.IResource such as t.w.static.File. Ifbranch=Trueis passed toroutethe returnedIResourcewill also be allowed to handle all children path segments. Sohttp://localhost:8080/static/img.gifshould return an image andhttp://localhost:8080/static/should return a directory listing.

from twisted.web.static import File  from klein import run, route    @route('/static/', branch=True)  def static(request):      return File("./static")    @route('/')  def home(request):      return '<img src="/static/img.gif">'    run("localhost", 8080)

项目主页:http://www.open-open.com/lib/view/home/1426560076414

</div>