Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Builder for CherryPy

After using werkzeug as a web framework (which is great and simple, but doesnt support some features), i'm now trying cherrypy.

Now what I miss in cherrypy is werkzeug's elegant way of building urls (e.g. for links in templates) using the name of a decorated function like this:

@expose('/archive/<int:year>/<int:month>')
def archive(request, year, month):
    pass

>>> url_for('archive',2010,04)
'/archive/2010/04'

I didn't find a similar way in cherrypy, did I miss it?

like image 916
tautologe Avatar asked Oct 03 '10 00:10

tautologe


1 Answers

You didn't miss it. CherryPy doesn't have that sort of approach built into the 'expose' decorator. You can, however, use the builtin Routes dispatcher with your application, which has a similar URL template syntax. If you'd like to try to wrap that up into a decorator like werkzeug's, we'd love to see the code pasted on the http://tools.cherrypy.org wiki. Bonus points for sticking that logic onto the RoutesDispatcher class itself.

like image 77
fumanchu Avatar answered Sep 21 '22 20:09

fumanchu