pass and display non-ASCII url with web.seeother()

28 views
Skip to first unread message

yongzh...@gmail.com

unread,
Apr 1, 2015, 4:59:18 PM4/1/15
to we...@googlegroups.com
Hi all,

In my case, I want to display several images according to a id. The url may looks like ~/genplots?id=20150401134514. I wrote "raise web.seeother('/genplots?id=%s' %(idstring))" with "    '/genplots\?id=(\d*)', 'genplots'". But it won't match url correctly and I got error message ""HTTP/1.1 GET /genplots" - 404 Not Found" with expected url in the browser's address field.

However, if I use encoding "raise web.seeother('/genplots'+'%3Fid%3D'+idstring)", it shows correct image set with message ""HTTP/1.1 GET /genplots?id=20150401134514" - 200 OK". But the url in the browser was "~/genplots%3Fid%3D20150401134725" rather than "~/genplots?id=20150401134725". Is there a way to fix this issue? I searched but didn't find proper example code. Thanks a lot.

Best Regards,
-Yongzhi

sam chen

unread,
Apr 2, 2015, 11:44:59 PM4/2/15
to we...@googlegroups.com
please paste all your urls rules here.


在 2015年4月2日星期四 UTC+8上午4:59:18,yongzh...@gmail.com写道:

tensio

unread,
Apr 3, 2015, 6:33:20 AM4/3/15
to we...@googlegroups.com
I think your URL pattern is broken. 
When you want to access a URL parameter like ?id=xyz use web.input() not a URL-pattern (http://webpy.org/cookbook/input).
So in the URLs use: 
'/genplots",'genplots',

and in the GET() method of your genplots class use:
url_data=web.input(id="no data") #the "no data" is a default value, if no id is given
url_id
= web.input().id

And if you want to redirect to an url with an parameter use:
raise web.seeother("/genplots"+"?id="+unicode(id_you_want)) #given  that the  id is an integer

I hope this helps. If not we could help better if we had more code. 

yongzh...@gmail.com

unread,
Apr 3, 2015, 10:17:39 PM4/3/15
to we...@googlegroups.com
Nice suggestion. Will try it and let you know the result. Thanks a lot.

Best Regards,
-Yongzhi

yongzh...@gmail.com

unread,
Apr 3, 2015, 11:15:22 PM4/3/15
to we...@googlegroups.com
Hello Tensio,

Your code works very well. I really appreciate it!


Best Regards,
-Yongzhi

On Friday, April 3, 2015 at 3:33:20 AM UTC-7, tensio wrote:
Reply all
Reply to author
Forward
0 new messages