url mapping

53 views
Skip to first unread message

Alex K

unread,
Nov 1, 2006, 6:53:12 AM11/1/06
to web.py
Hello,

How can I look for '?' in the url mapping regex. I tried to escape it
using \? but it seems web.py further escapes the \ by writting \\?.

Here is my code:

import web
urls = (
'/search\?', 'search',
)

class search:
def GET(self):
print 'hello'

if __name__ == '__main__':
web.run(urls, web.reloader)

Printing the web.py mapping gives:

('/search\\?', 'search')

Looking up for the url .../search? gives not found. Interestingly the
web.py url mapping for (search\d+, search) gives (search\\d+, search)
but looking for the url .../search23 works.

Thank you,

Alex

Aaron Swartz

unread,
Nov 1, 2006, 8:06:58 AM11/1/06
to we...@googlegroups.com
The ? gets processed by the query argument reader (e.g. for
/search?q=5) and so isn't available when you look up URLs.

Alex K

unread,
Nov 1, 2006, 9:43:52 AM11/1/06
to web.py
Pardon my newbie but what would be the cleanest way to process url
parameters then? I can always have the regex /search(.*) for the url
/search?q=hello, but that does not seem completely satisfactory. Thank
you.

Aaron Swartz

unread,
Nov 1, 2006, 9:49:03 AM11/1/06
to we...@googlegroups.com
If you just do web.input() you'll get back a dictionary of URL parameters.

David Terrell

unread,
Nov 1, 2006, 1:18:22 PM11/1/06
to we...@googlegroups.com
On Wed, Nov 01, 2006 at 02:43:52PM -0000, Alex K wrote:
>
> Pardon my newbie but what would be the cleanest way to process url
> parameters then? I can always have the regex /search(.*) for the url
> /search?q=hello, but that does not seem completely satisfactory. Thank
> you.


URLS = ('/search', 'Search', ....)

class Search:
def GET(self):
i = web.input()
q = i.q;
# q = 'hello'

--
David Terrell
d...@meat.net
((meatspace)) http://meat.net/

Reply all
Reply to author
Forward
0 new messages