django:搜索表单和重定向
处理来自 POST 的表单后,我应该重定向,以防止用户回击。但是,我使用表单来确定数据库上的搜索查询,因此我需要将参数传递到重定向站点或搜索结果。或者也许还有其他一些好的做法,如何解决这个问题?也许在这种情况下,我可以不重定向(如果用户再次执行搜索,则不会发生任何情况)。
After processing form from POST I should redirect, to prevent user from hitting back. However, I am using form to determine search query on a database, so I need to either pass params to the redirected site or the result of a search. Or maybe there is some other good practice, how to solve this problem? Maybe in this situation I am allowed not to redirect (nothing happens, if user performs search again).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
搜索查询可能应该是 GET,而不是 POST,因为它们不会改变任何内容 - 它们只是传递参数来获取某些信息。 POST 应该保留用于实际更改数据库中的内容或导致特定操作(例如提交电子邮件)的表单。
要回复您的评论,隐藏 URL 中的参数并不是特别好的做法,但如果您确实认为需要这样做,那么在这种情况下,可以在表单提交后不重定向 - 再次,因为您不会影响任何内容邮报。
Search queries should probably be GETs, rather than POSTs, because they are not changing anything - they are simply passing parameters to get certain information. POST should be reserved for forms that actually change things in the database, or result in a specific action (eg submitting an email).
To reply to your comment, hiding parameters from URLs is not particularly good practice, but if you really think you need to, this is an instance where it's OK not to redirect after the form submission - again, because you're not affecting anything with the POST.