How do I pass a url as a url parameter when there is a question mark in it?

I use this line to pass a url , main_id and user_tag_list to the handler:

 self.response.out.write(""" <a href="/tc?url=%s&main_id=%s&user_tag_list=%s" title="edit tag set">edit tag set</a> """ % (item.url, main_id, item.tag_list)) 

this works fine except that when the passed url (first parameter) already has a question mark, I can no longer get main_id with

 main_id = self.request.get("main_id") 

in the target handler, instead I get an error

 m = Main.get_by_id(int(main_id)) ValueError: invalid literal for int() with base 10: '' 

Is there any way around this?

+6
python google-app-engine url-parameters
source share
2 answers

You just want to use urllib.quote

 >>> import urllib >>> urllib.quote('http://www.google.com?q=Zombie+Apocalypse') 'http%3A//www.google.com%3Fq%3DZombie%2BApocalypse' 

So:

 urllib.quote(item.url) 
+9
source share

urllib.quote should help with this.

+1
source share

All Articles