wsgi路由设备。

decorouter的Python项目详细描述


decorouter是一种wsgi路由设备,它使定义路由变得容易 使用decorator语法。

示例:

from decorouter import Router

class MyApplication:
    router = Router()

    @router.add('/$')
    def index(self, environ, start_response):
        start_response('200 OK', [('Content-type', 'text/plain')])
        return ['Hello, world!']

    @router.add('/hello/([^/]+)$')
    def index(self, environ, start_response):
        args, kwargs = environ['wsgiorg.routing_args']
        (name,) = args
        start_response('200 OK', [('Content-type', 'text/plain')])
        return ['Hello, %s!' % (name,)]

    def __call__(self, environ, start_response):
        return self.router(environ, start_response)

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    make_server('', 8000, MyApplication()).serve_forever()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
我可以用C++代码使用java代码吗?   java使用JSR303在派生类中提供更具体的约束   java在这个查找唯一路径数算法中我做错了什么?   java如何为2个不同的服务提供商使用2个不同的SSL证书?   java在Gridview上绘制文本   java使用连接for循环构建字符串名   java StringBuilder拆分无法处理某些文件   java事件关注EditText   Java Web Start“找不到URL的缓存资源”   java程序从命令行运行的速度比在Eclipse中慢   java为什么HttpServletRequest会截断#字符上的url输入?   java自定义折叠工具栏平滑标题大小调整   使用Mockito对安卓 java中调用另一个静态函数的函数进行单元测试   http在java客户机中使用cachecontrol头   java如何使用。是否使用Delimiter从输入文件中排除标点符号和数字?   使用上下文作为参数/参数的java   java更有效地从Jar中提取文件   java为多个JButton提供相同的actionListener