Python web服務的微型框架:Klein

jopen 9年前發布 | 25K 次閱讀 Klein Web框架

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.baiduhome.net/lib/view/home/1426560076414

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!