1. cherrypy
  2. CherryPy
Issue #1010 resolved

Routes Dispatcher doesn't work with Routes 1.12.1

Chris Mulligan
created an issue

I tried a simple HelloWorld example for the routes dispatcher and kept running intro trouble. In the end it turns out that the current version of Routes (1.12.1) was incompatible. Every URL I tried, including "/", explicitly defined and implicitly defined were all 404.

After discussing it in #cherrypy I downgraded to Routes 1.10.3 and everything worked perfectly. Further testing reveals that routes 1.11 works too. It seems to be 1.12 that breaks the RoutesDispatcher.

Example app: {{{


import cherrypy import random

class Example: @cherrypy.expose def index(self): return "Hello World!"

class Random: @cherrypy.expose def index(self, stuff): return "Random %s: %s" % (stuff, random.random())

mapper = cherrypy.dispatch.RoutesDispatcher() mapper.connect('index', '', Example()) mapper.connect('index', '/', Example()) mapper.connect('index', 'foobar', Example()) mapper.connect('random', '/:stuff', Random())

conf = { '/' : {'request.dispatch' : mapper}, }

if name == "main": cherrypy.tree.mount(root=None, config=conf) cherrypy.quickstart(None, config=conf) }}}

Comments (3)

  1. Anonymous

    In Routes 1.12 a default was changed that made the route mapper “explicit” by default. See [http://routes.groovie.org/changes.html#release-1-12-february-28-2010]. This means (I believe) that routes will not be given the defaults of "action=index" and "controller=content". As a result cherrypy isn’t able to figure out what method to dispatch in your example app because it doesn’t know what “action” the route corresponds to.

    You should be able to fix any of the routes by adding either action="index" (to explicitly define an action), or _explicit=False (to re-enable the default controller and action) as keyword arguments for your connect call.

  2. Jason R. Coombs

    After inspecting the code, I found that the old behavior can be re-enabled by setting the `explicit` attribute to False on the mapper.

    >>> disp = cherrypy.dispatch.RoutesDispatcher()
    >>> mapper = disp.mapper
    >>> mapper.explicit = False
    >>> disp.connect(...) # or mapper.connect(...)
  3. Log in to comment