Re: [webpy] Can't get basic routes working.
Hey Marios, Thanks. That got me going. I now have working routes. I found route ordering to be important. I have my "catch all" route defined last in my urls. urls = ( '/foo(.*)', 'foo', '/bar(.*)', 'bar', '/(.*)', 'index') Thanks again. Rob. On Friday, 14 October 2016 15:41:51 UTC+1, Marios Zindilis wrote: > > This is somewhat documented in http://webpy.org/cookbook/url_handling but > it might not be clear enough. > > Both your classes' GET methods require a "name" parameter, but you are not > capturing that name in your URL definitions. When you define a URL as > ('/bob', 'bob'), as soon as a request matches the first part, it calls > bob.GET() without any parameters. If you add a capture to your URL > definitions, such as ('/bob/(.*)', 'bob') then web.py will pass whatever it > captures after "/bob/" as a parameter to bob.GET(). > > I hope this is clear. > > -- > Marios > > On Fri, Oct 14, 2016 at 3:20 PM, robsbots > wrote: > >> I can't seem to get the basics of routing working. >> >> This is my code. >> >> #!/usr/bin/env python >> >> # Imports >> import web >> >> # Variable definition >> urls = ( >> # '/(.*)', 'hello', >> '/', 'hello', >> '/bob', 'bob') >> >> app = web.application(urls, globals()) >> >> # Main class >> class hello: >> def GET(self, name): >> print ( "Name for class - " ), >> print ( name ) >> http_response = "Hello, world!" >> return http_response >> >> class bob: >> def GET(self, name): >> http_response = "Hello, bob!" >> return http_response >> >> >> # Call web.py app >> if __name__ == "__main__": >> app.run() >> >> This code gives me 'TypeError: GET() takes exactly 2 arguments (1 given)' >> when I request any route. If I replace the URLS variable with a catchall, >> this works as expected. >> >> What am I missing ? >> >> Thanks. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "web.py" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to webpy+un...@googlegroups.com . >> To post to this group, send email to we...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/webpy. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Marios Zindilis > -- You received this message because you are subscribed to the Google Groups "web.py" group. To unsubscribe from this group and stop receiving emails from it, send an email to webpy+unsubscr...@googlegroups.com. To post to this group, send email to webpy@googlegroups.com. Visit this group at https://groups.google.com/group/webpy. For more options, visit https://groups.google.com/d/optout.
Re: [webpy] Can't get basic routes working.
This is somewhat documented in http://webpy.org/cookbook/url_handling but it might not be clear enough. Both your classes' GET methods require a "name" parameter, but you are not capturing that name in your URL definitions. When you define a URL as ('/bob', 'bob'), as soon as a request matches the first part, it calls bob.GET() without any parameters. If you add a capture to your URL definitions, such as ('/bob/(.*)', 'bob') then web.py will pass whatever it captures after "/bob/" as a parameter to bob.GET(). I hope this is clear. -- Marios On Fri, Oct 14, 2016 at 3:20 PM, robsbots wrote: > I can't seem to get the basics of routing working. > > This is my code. > > #!/usr/bin/env python > > # Imports > import web > > # Variable definition > urls = ( > # '/(.*)', 'hello', > '/', 'hello', > '/bob', 'bob') > > app = web.application(urls, globals()) > > # Main class > class hello: > def GET(self, name): > print ( "Name for class - " ), > print ( name ) > http_response = "Hello, world!" > return http_response > > class bob: > def GET(self, name): > http_response = "Hello, bob!" > return http_response > > > # Call web.py app > if __name__ == "__main__": > app.run() > > This code gives me 'TypeError: GET() takes exactly 2 arguments (1 given)' > when I request any route. If I replace the URLS variable with a catchall, > this works as expected. > > What am I missing ? > > Thanks. > > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to webpy+unsubscr...@googlegroups.com. > To post to this group, send email to webpy@googlegroups.com. > Visit this group at https://groups.google.com/group/webpy. > For more options, visit https://groups.google.com/d/optout. > -- Marios Zindilis -- You received this message because you are subscribed to the Google Groups "web.py" group. To unsubscribe from this group and stop receiving emails from it, send an email to webpy+unsubscr...@googlegroups.com. To post to this group, send email to webpy@googlegroups.com. Visit this group at https://groups.google.com/group/webpy. For more options, visit https://groups.google.com/d/optout.
[webpy] Can't get basic routes working.
I can't seem to get the basics of routing working. This is my code. #!/usr/bin/env python # Imports import web # Variable definition urls = ( # '/(.*)', 'hello', '/', 'hello', '/bob', 'bob') app = web.application(urls, globals()) # Main class class hello: def GET(self, name): print ( "Name for class - " ), print ( name ) http_response = "Hello, world!" return http_response class bob: def GET(self, name): http_response = "Hello, bob!" return http_response # Call web.py app if __name__ == "__main__": app.run() This code gives me 'TypeError: GET() takes exactly 2 arguments (1 given)' when I request any route. If I replace the URLS variable with a catchall, this works as expected. What am I missing ? Thanks. -- You received this message because you are subscribed to the Google Groups "web.py" group. To unsubscribe from this group and stop receiving emails from it, send an email to webpy+unsubscr...@googlegroups.com. To post to this group, send email to webpy@googlegroups.com. Visit this group at https://groups.google.com/group/webpy. For more options, visit https://groups.google.com/d/optout.