On Sunday, July 31, 2016 at 2:39:17 AM UTC-4, Massimo Di Pierro wrote: > > This is a limitation with routes out. The left hand side cannot contain > "?" and vars. > You can maps path_info into request.vars in the way but not the vice versa > in the way out. You have to put the language in the args and the do the > remapping on the way out. > > On Friday, 29 July 2016 23:12:07 UTC-5, Carlos Cesar Caballero wrote: >> >> Hi everyone, again with problems with the router here, I have this rule >> in routes_in, and is working pefectly: >> >> ('/$lang/$country/$state/$city(?P<any>.*)', >> '/{app}/city/view\g<any>?lang=$lang&country=$country&state=$state&city=$city'.format(app=app)) >> >> This maps the url and I can use the language, the country, the city and >> the state as variables in my controller, the problem is with the routes_out: >> >> ( >> '/{app}/city/view(?P<any>.*)?lang=$lang&country=$country&state=$state&city=$city'.format(app=app), >> >> '/$lang/$country/$state/$city\g<any>') >> > Sorry, didn't realize you can't map an outgoing query string to the URL path. Instead, though, you should be able to use URL args instead of vars for the outgoing URLs. So, routes_out would look something like:
routes_out = [ ('/{app}/city/view/$lang/$country/$state/$city(?P<any>.*)'.format(app= app), '/$lang/$country/$state/$city\g<any>') ] Then generate URLs like this: URL('city', 'view', args=[request.vars.lang, request.vars.country, request.vars.state, request.vars.city, "other", "args"]) If using the grid, you would need to do: SQLFORM.grid(..., args=[request.vars.lang, request.vars.country, request.vars. state, request.vars.city]) To simplify, in a model you could do: fixed_args = [request.vars.lang, request.vars.country, request.vars.state, request.vars.city] and then use fixed_args where needed (maybe also write a special url() helper function to automatically add those args to all URLs). Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.