Reputation: 562
I want to search by query, like a below.
http://localhost:8080/search?query=a
html
...
<form class="navbar-form navbar-right" name="searchform" action="/search" method="post">
<div class="form-group">
<input class="form-control" placeholder="Any keyword" type="text" name="query" />
</div>
<button class="btn btn-success" type="submit">Search</button>
</form>
...
routes.py
...
import handlers
_routes = [
RedirectRoute('/search?query=<.*>', handlers.SearchHandler, name='search', handler_method='post')
]
...
handlers.py
...
class SearchHandler(BaseHandler):
def get(self):
params = {
'query': '',
'offset': '0'
}
self.doSearch(params)
def doSearch(self, params):
docs = search.Index(name='indexed_doc')
query = params.get('query', '')
try:
offset_value = int(params.get('offset' or 0))
except ValueError:
offset_value = 0
try:
search_query = search.Query(...
result against: '/search?query=<.*>' at routes.py
error_handler.py:71] Error 403: Access was denied to this resource.
module.py:593] default: "POST /search HTTP/1.1" 403 2555
result against: '/search(.*)' at routes.py
error_handler.py:71] Error 404: The resource could not be found.
module.py:593] default: "POST /search HTTP/1.1" 404 2543
How can I coding regex for it? or what is wrong?
Thanks in advance.
Upvotes: 1
Views: 139
Reputation: 55962
I believe there are a couple issues:
RedirectRoute
? is it necessary to redirect on post request?query
) should be stored in the request body, not in the url, like /search?query=a+query
you could change to get request:
<form class="navbar-form navbar-right" name="searchform" action="/search" method="get">
<div class="form-group">
<input class="form-control" placeholder="Any keyword" type="text" name="query" />
</div>
<button class="btn btn-success" type="submit">Search</button>
</form>
import handlers
_routes = [
('/search', handlers.SearchHandler, name='search')
]
Upvotes: 3