I want to create a search box in Django that is situated at the URL /search, and redirects to a friendly URL like /search/queryterm - rather than having ?q=queryterm in the URL)
So the user types in a query term, it takes them 开发者_开发百科to /search/queryterm, and shows a list of results.
I can get and display the results OK given a URL like /search/queryterm.
But I don't know the best way to handle the URL redirect from the form. Should this be a redirect in pure HTML in the form (which feels slightly hacky), and if so, how can I implement this?
Or should the form POST to /search/, then ResponseRedirect to the /search/queryterm page? Wouldn't this be slower?
Thanks!
POSTing a search query is a bad idea and a misuse of the HTTP verb for what ought to be a GET request, I think. Is there any reason you can not redirect to a friendly URL based on the request.GET
parameters?
I also disagree with the principle of using "friendly" URLs for search queries; they should be used for permanent resources rather than something transient like search results, in my opinion.
The reason there has been a fightback of sorts for "friendly" URLs is because querystrings were being abused for accessing things that should exist at plain URLs, like /product.php?id=35
. I don't think search results fall into this category.
精彩评论