How to add search term to the url of the handler?

30 views
Skip to first unread message

Zeynel

unread,
Sep 17, 2011, 9:01:33 PM9/17/11
to Google App Engine
There was no answer to this question at Stackoverflow.

http://stackoverflow.com/questions/7456670/how-do-i-add-search-parameters-to-search-page-url

This is the form:

self.response.out.write("""
<form name="search_form" action="/searchhandler" method="post"><br />
<input type="text" name="search_string" size=40>
<input type="submit" value="search tags">
</form>""")

and this is the SearchHandler:

class SearchHandler(webapp.RequestHandler):
def post(self):
...

s = filter(None,
f1.striplist(self.request.get("search_string").split("
")))
n = len(s)

if n==1:
query = Main.all()
query.filter("tag_list", s[0])
query.order("-total_value")

f1.display(query, self) #a function that displays the search
results
...

In SearchHandler I checked and

self.request.get("search_string")

correctly gives the search string but I could not figure out how to
put that in the url like

/searchhandler?search_string=[search string]

Thanks!

Jose Montes de Oca

unread,
Sep 20, 2011, 7:57:53 PM9/20/11
to google-a...@googlegroups.com
Hi,

When using a form with POST, the attributes are not send thru the URL but are within the message body of the request. 

If you would like your app to react to an URL of the type: /searchhandler?search_string=[search string]  you will need to code the get() method for the handler. If you access that URL from your browsers, it will send the request as a GET method.

Hope this helps!

Jose Montes de Oca
Reply all
Reply to author
Forward
0 new messages