pyGrowlerPython Web框架
pyGrowler 是在PEP 3156和 Python 3.4 標(biāo)準(zhǔn)下,利用全新的異步庫開發(fā)的Web框架。受NodeJS擴(kuò)展庫的啟發(fā), pyGrowler也采用通過一系列的中間件來處理HTTP請求。同時,高可定制性的中間件對處理復(fù)雜的應(yīng)用程序極為方便。
使用示例代碼:
import asyncio
from growler import App
from growler.middleware import (Logger, Static, Renderer)
loop = asyncio.get_event_loop()
# Construct our application with name GrowlerServer
app = App('GrowlerServer', loop=loop)
# Add some growler middleware to the application
app.use(Logger())
app.use(Static(path='public'))
app.use(Renderer("views/", "jade"))
# Add some routes to the application
@app.get('/')
def index(req, res):
res.render("home")
@app.get('/hello')
def hello_world(req, res):
res.send_text("Hello World!!")
# Create the server - this automatically adds it to the asyncio event loop
Server = app.create_server(host='127.0.0.1', port=8000)
# Tell the event loop to run forever - this will listen to the server's
# socket and wake up the growler application upon each connection
loop.run_forever()評論
圖片
表情
