why not have a dictionary? controllers = {'route-me-if-you-can': any_time_you_want} if lookup misses method name is searched as it is?
The admin interface could expose a way to do it easy. mic 2010/8/25 Jonathan Lundell <jlund...@pobox.com>: > On Aug 25, 2010, at 1:42 AM, Kevin wrote: > >> It would be safe for the routing code to treat hyphens as underscores >> when matching for app, controller, or function, though -- since web2py >> (and python) semantics require that the code itself uses underscores. >> Of course underscores in the rest of the URL would have to pass >> through untouched. > > Are Python restrictions relevant for applications and controllers? Or just > filename restrictions? I'm not sure. > >> >> Reverse translation is not an issue, since I could just do something >> like: >> >> {{= DASH(URL(...)) }} >> >> Where DASH replaces all underscores with hyphens (which is acceptable >> for me, since I don't use any underscores in URLs), though it would be >> handy to make the routes.py configurable to do that automatically in >> the URL call itself if I wanted. > > It could be an option to URL, I suppose. I'm thinking that you wouldn't want > to translate underscores in the query string. > >> >> On Aug 24, 9:46 pm, Jonathan Lundell <jlund...@pobox.com> wrote: >>> On Aug 24, 2010, at 8:03 PM, Kevin wrote: >>> >>>> As far as I can find, you have to set up web2py routes to do this -- >>>> it's pretty easy to do redirection using routes (using routes_in), but >>>> I'm not aware of any way off-hand to do the equivalent of rewriting/ >>>> translation the URL for inbound requests (routes_out does to >>>> translation). >>> >>> I think it would be difficult, unless you explicitly translated known >>> controller names. Which you could do... >>> >>> We could translate incoming hyphens to underscores, I suppose, without too >>> much effort, but we wouldn't know whether to reverse the translation on the >>> outbound side. >>> >>> Come the revolution (new rewrite logic), all things will be possible. But >>> no promises on a schedule. >>> >>> We *could* simply allow hyphens in controller names, without translation. >>> We can't do that with functions, since they need to function as Python >>> identifiers. >>> >>> >>> >>>> This is something I (and doubtless) many others need as well, and it >>>> really should be a (default enabled) option for web2py to >>>> automatically treat URL-embedded hyphens as though they were >>>> underscores for matching app, controller and function names, and an >>>> optionally enablable setting to make all generated routes use hyphens >>>> instead of underscores for apps, controllers, and functions. >>> >>>> The open-and-shut arguments for using hyphens boil down to (in order >>>> of severity): >>> >>>> * Underscores are obscured when URLs are underlined >>>> * Hyphens are easier to type than underscores – no need for the shift >>>> key >>>> * Hyphens are easier to read >>>> * Underscores are a typographical construction invented primarily for >>>> underlining characters (<key> <backspace> <underscore> on a >>>> typewriter), and today is used primarily in programming and other >>>> technical contexts. In short, there is little justification for >>>> exposing back-end considerations to the world. >>> >>>> Many references can be found on this subject: >>> >>>> *http://pylonsbook.com/en/1.1/urls-routing-and-dispatch.html#choosing-... >>>> *http://semicolons.org/post/256699383/friendly-urls >>>> *http://www.wordsellinc.com/blog/content-optimization/use-hyphens-not-... >>> >>>> This is one of the sore points I have with anything I put on the web >>>> -- to provide what I feel is a correct URL scheme to the user, I'll >>>> bypass or override half of the backend code if necessary, which is >>>> suboptimal. >>> >>>> Web2py is very close to making it easy to provide URLs that'll >>>> withstand the scrutiny of bloggers -- besides the hyphen bit, all I >>>> really see as being needed is: >>> >>>> * The aforementioned settings for hyphenization. >>> >>>> * in routes_in and routes_out add the ability to supply a function/ >>>> lambda in the second index of any inner two-tuple, which would receive >>>> a match object and return a string. For example, the following could >>>> be a stop-gap way to perform this kind of underscore-to-hyphen >>>> conversion: >>> >>>> routes_out = ( (r'/([^/]*)/([^/]*)/([^/]*)(/?P<any>.*)?', >>>> lambda match: '/'.join(part.replace('_', '-') for part in >>>> match.groups()) + match.group('any')), ) >>> >>>> On Aug 24, 7:47 pm, Cory Coager <ccoa...@gmail.com> wrote: >>>>> How do you use dashes in controller names? I get errors, "Invalid >>>>> request". >>> >>> > > >