处理多余的参数

code

import cherrypy

class Band(object):
    def __init__(self):
        self.albums = Album()
    def _cp_dispatch(self, vpath):
        if len(vpath) == 1:
            cherrypy.request.params['name'] = vpath.pop()
            return self
        if len(vpath) == 3:
            #cc,bb,aa
            cherrypy.request.params['artist'] = vpath.pop(0) # cc
            vpath.pop(0) # bb
            cherrypy.request.params['title'] = vpath.pop(0) # aa
            return self.albums
        return vpath

    @cherrypy.expose
    def index(self, name):
        return 'About %s...' % name

class Album(object):
    @cherrypy.expose
    def index(self, artist, title):
        return 'About %s by %s...' % (title, artist)


if __name__ == '__main__':
    cherrypy.quickstart(Band())

效果图

效果图

 

posted @ 2020-12-23 15:38  anobscureretreat  阅读(122)  评论(0编辑  收藏  举报