pyGrowler - Python Web框架


Apache 2.0
跨平台
Python

软件简介

pyGrowler 是在PEP 3156和 Python 3.4
标准下,利用全新的异步库开发的Web框架。受NodeJS扩展库的启发,
pyGrowler也采用通过一系列的中间件来处理HTTP请求。同时,高可定制性的中间件对处理复杂的应用程序极为方便。

使用示例代码:

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()