On Sun, Oct 25, 2009 at 7:07 AM, [email protected] <[email protected]> wrote: > > We have url format like > http://www.example.com/search?fsid=software&fgid=language&fcid=python > > Now we want to change without using query string with ? mark. > > So we come up with the following format. > > http://www.example.com/search/fsid-software/fgid-language/fcid-python > > we have more filters than in the above example specified above. > > search is the name of the controller. Now we need to get the fsid- > software, fsid-language and fcid-python into the search controller > index method. > > They are not really argument and the order could change. > > 1. http://www.example.com/search/fsid-software/fgid-language/fcid-python > 2. http://www.example.com/search/fgid-language/fcid-python/fsid-software > 3. http://www.example.com/search/fgid-all/fcid-python/fsid-software > > Other complicated problem is to use of query string for pagination. > Pagination arguments to be passed as a query string. > > Can you suggest me, > > 1. How to receive the http://www.example.com/search/* into a single > function argument with differentiation in the query string. Otherwise > 2. How to receive them as a python keywords args or a list > > Either way, I can handle the query well.
If you want to put moveable variables in the URL, the proper way is with URL parameters. (http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax) http://www.example.com/search;fsid=software;fgid=language;fcid=python However, this part of the URL specification has rarely if ever been used. Routes does not support it natively, so you'd have to pass the whole parameter section as a wildcard. map.connect("search", "/search;{spec:.*}", ...) This would make the 'spec' variable contain "fsid-software/fgid-language/fcid-python". You would then have to parse it in the action. Maybe: for component in spec.split("/"): name, value = component.split("=") ... As to putting moveable parameters in the URL path, it conflicts with four principles of URL design: - There should be exactly one URL to a resource. - The components of a URL path should not move. - Each component should contain the one on its right. - If you need to support legacy URLs after a reorganization, the old URLs should redirect to the new ones using "301 Moved Permanently". So the best thing to do is to choose a single hierarchy and set up a route for it: map.connect("search", "/search/{fsid}/{fgid}/{fcid}", ...) The variable names are unnecessary in the URL because the positions are fixed. The names are unnecessary to the application, and are unreadable by humans anyway (how many people know what fsid means?) But if you really want the names, you can do this: map.connect("search", "/search/fsid-{fsid}/fgid-{fgid}/fcid-{fcid}", ...) If you want the components to move, you'll have to define routes for all nine combinations, or use a wildcard like above. Any choice is compatible with a 'page' query parameter. The webhepers.paginate module is designed for a query parameter 'page'. -- Mike Orr <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
