表单重定向到包含查询词的URL? -纯HTML或Django [英] Form redirect to URL containing query term? - pure HTML or Django

查看:72
本文介绍了表单重定向到包含查询词的URL? -纯HTML或Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Django中创建一个搜索框,该搜索框位于URL / search处,并重定向到一个友好的URL,例如/ search / queryterm-而不是在URL中使用?q = queryterm)

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)

因此,用户输入查询词,将其带到/ search / queryterm,并显示结果列表。

So the user types in a query term, it takes them to /search/queryterm, and shows a list of results.

I给定像/ search / queryterm这样的URL,就可以获取并显示结果。

I can get and display the results OK given a URL like /search/queryterm.

但是我不知道处理来自表单的URL重定向的最佳方法。

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?

还是应该以POST形式/来实现纯HTML格式的重定向(感觉有点hacky)? search /,然后ResponseRedirect重定向到/ search / queryterm页面?

Or should the form POST to /search/, then ResponseRedirect to the /search/queryterm page? Wouldn't this be slower?

谢谢!

推荐答案

发布我认为,搜索查询是一个坏主意,并且误将HTTP动词用于应为GET请求的内容。您是否有任何原因无法根据 request.GET 参数重定向到友好的URL?

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?

我也不同意使用友好 URL进行搜索查询的原则;在我看来,它们应该用于永久性资源,而不是诸如搜索结果之类的暂时性资源。

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.

对友好 URL进行了某种反击是因为查询字符串被滥用来访问应该在简单URL中存在的内容,例如 /product.php?id=35 。我认为搜索结果不属于此类。

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.

这篇关于表单重定向到包含查询词的URL? -纯HTML或Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆