Routes Dispatcher doesn't work with Routes 1.12.1

chmullig avatarchmullig 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:
    def index(self):
		return "Hello World!"
class Random:
    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 []. 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.