Django 表单:混合请求提交(get 和 post)

发布于 2024-12-10 13:20:50 字数 537 浏览 1 评论 0原文

由于我的项目中与 SEO 相关的原因,我必须在 url 中捕获某些搜索参数以获取“美丽的 url”。

高级搜索由 7 个参数组成,其中 3 个与位置相关,也是我们的 seo 顾问感兴趣的参数。

所以,现在我有点困惑。自从我开始专业使用 django 以来已经有一段时间了,但从未遇到过这样的问题。基本上,最终的 url 结构必须是这样的:

/Italy/Lombardy/Milan/?price=100&miles=10&last_posted=2

我的 urls.py 现在是

'/(?P<country>\w+)/(?P<zone>\w+)/(?P<city>\w+)/$', SearchView.as_view()

,我不确定的是我应该如何在表单方法中指定我的请求才能使用确切的 url 模式?发布还是获取?当用户输入时,如何动态地编写“action”属性的 url?这是正确的解决方案吗?我真的很困惑,任何帮助将非常感激!谢谢!

for seo related reason in my project i have to trap certain search parameters within the url for the "beautiful url" thing.

The advanced search is composed by 7 parameters, 3 of which are location-related and are the ones interesting our seo consultant.

So, now i'm a bit confused. It's been a while since i started using django professionally, but never had to face an issue like this. Basically, the final url structure must be something like this:

/Italy/Lombardy/Milan/?price=100&miles=10&last_posted=2

and my urls.py is

'/(?P<country>\w+)/(?P<zone>\w+)/(?P<city>\w+)/

now, what i'm not sure about is how should i specify my request in the form method to be able to use that exact url schema? POST or GET? And how can i compose the url for the "action" attribute dynamically while the user types? Is this even the correct solution? I'm really confused about it, any help would be really appreciated! Thanks!

, SearchView.as_view()

now, what i'm not sure about is how should i specify my request in the form method to be able to use that exact url schema? POST or GET? And how can i compose the url for the "action" attribute dynamically while the user types? Is this even the correct solution? I'm really confused about it, any help would be really appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找我们的幸福 2024-12-17 13:20:50

您必须使用脚本更改表单的操作字段,是的。并将方法设置为 GET,并在表单中仅包含查询字符串中出现的字段。

you will have to change the action field of the form using script, yes. and set the method to GET, and include in the form only the fields appearing in the query string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文