简体   繁体   English

通过网址“隐藏”表单查询(Django 1.3)

[英]'Hiding' form query from URL (Django 1.3)

I have a form with 6-7 fields. 我有一个包含6-7个字段的表格。 After user input, my webapp searches for those fields in a database and displays the results. 用户输入后,我的Web应用程序将在数据库中搜索这些字段并显示结果。 Now the issue is, that the URL ends up having all the form field names and their values in it. 现在的问题是,URL最终将包含所有表单字段名称及其值。

result/?name=lorem&class=arc&course=ipsum

Now with the form having 7-8 fields the url ends up looking ugly. 现在具有7-8个字段的表单,URL看起来很难看。 Is there a Django technique to 'hide' these from the URL? 是否有Django技术可从网址“隐藏”这些内容? Quotes around hide because I'd be okay with a completely different way to pass the objects to my database from the form as well. 隐藏报价,因为我也可以采用完全不同的方式将对象从表单传递到数据库。

Use a POST request . 使用POST请求 Here's the django docs on forms and a specific example using POST>. 这里的表单上的Django文档和一个具体的例子使用POST>。 HTML-wise, all you need to do is change the method on the form tag. HTML明智的,你需要做的是改变对方法form标记。

I do not recommend to use POST requests for search. 我不建议使用POST请求进行搜索。 If you'll use GET it will be easer for user, he can just bookmark a link and save search or share search results with friends. 如果您将使用GET,它将使用户更轻松,他可以将链接添加为书签并保存搜索或与朋友共享搜索结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM