dimanche 4 août 2019

How to use regex url in CherryPy?

I am trying to add regex url to CherryPy, but for some reason everything doesn’t work out, what am I mistaken?

I need url opts to look like example.com/opts/someopts. But now with such a request I get 404.

 SomeClass:
    def __init__(self, config):
         someactions

    @cherrypy.expose
    def opts(self):
        templ = Template(filename='dyn/opts.tmpl', lookup=self.lookup)
        self.token = random.randint(0, 99999999)
        return templ.render(opts=self.config, pageid='SETTINGS', 
        token=self.token, docroot=self.docroot)

    d = cherrypy.dispatch.RoutesDispatcher()
    d.connect(action='opts', name='opts', route='/opts/:optsname', 
    controller=opts)

    conf = {
        '/opts': {
             'request.dispatch': d
         },
    }
    cherrypy.tree.mount(root=None, config=conf)




Aucun commentaire:

Enregistrer un commentaire