[google-appengine] Re: Working with mappings
On Sat, Jan 3, 2009 at 10:02 PM, MajorProgamming wrote: Firstly, Do these mappings also support regular expression mappings? They *are* regular expressions. That's how those expressions are evaluated. Secondly, How can I use dynamic mappings (like instead of http://example.com/article?id=20 -- http://example.com/article/20)? ('/article/([\d]+)', Article) With the above rule, the matched values are passed to the handler, in order. So in Article you'll have the method get(self, article_id), which receives the article id from the matched rule. [and is there any advantage to doing query strings in this fashion?] Well, sometimes query strings are more convenient, but in many times you would want to certify that only url's with minimally valid parameters (in the above example, an integer) will match. With ?id=20, you'll have to check if an id is passed in the handler method, *after* the dispatch process. It's also a matter of aesthetics and, most important, how your handlers are organized. -- rodrigo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Working with mappings
What's passed to the article_id parameter? How does GAE know what to pass? On Jan 3, 7:58 pm, Rodrigo Moraes rodrigo.mor...@gmail.com wrote: On Sat, Jan 3, 2009 at 10:02 PM, MajorProgamming wrote: Firstly, Do these mappings also support regular expression mappings? They *are* regular expressions. That's how those expressions are evaluated. Secondly, How can I use dynamic mappings (like instead of http://example.com/article?id=20--http://example.com/article/20)? ('/article/([\d]+)', Article) With the above rule, the matched values are passed to the handler, in order. So in Article you'll have the method get(self, article_id), which receives the article id from the matched rule. [and is there any advantage to doing query strings in this fashion?] Well, sometimes query strings are more convenient, but in many times you would want to certify that only url's with minimally valid parameters (in the above example, an integer) will match. With ?id=20, you'll have to check if an id is passed in the handler method, *after* the dispatch process. It's also a matter of aesthetics and, most important, how your handlers are organized. -- rodrigo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Working with mappings
On Sat, Jan 3, 2009 at 11:16 PM, MajorProgamming wrote: What's passed to the article_id parameter? The digits extracted from the matched url - using the rule regexp as below: ('/article/([\d]+)', Article) How does GAE know what to pass? It simply passes all values captured by the regexp. Your handler method will receive as many values as the regex captures. Take a look at google.appengine.ext.webapp.__init__.py: the magic happens in WSGIApplication.__call__ For a bit more sophisticated / flexible routing mechanisms, see Routes or Werkzeug's routing: http://routes.groovie.org/ http://werkzeug.pocoo.org/documentation/routing -- rodrigo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---