具有多个可选参数的url [英] url with multiple optional arguments
问题描述
现在我有一个视图来显示有关某些票证的信息,我正尝试添加一种功能来过滤那些票证。
right now I have a view to show info about some tickets and I'm trying to add a functionality to filter those tickets.
说我将有4个过滤器:
- 日期
- 所有者
- 类别
- 状态
- Date
- Owner
- Category
- Status
类别状态
我想提供使用某些过滤器的选项,全部或全部不使用,问题是我有点不知道该如何在网址中使用它。到目前为止,我发现您可以添加一些可选参数,但是它们会以某种顺序出现,例如:
I want to give the option to use some of those filters, all or none, the thing is I'm kinda lost in how can I make it work in the urls. So far I found that you can add some optional arguments but they appear in some sort of succession like:
/ May / Jack / Gas / Accepted
/May/Jack/Gas/Accepted
但是,如果我仅选择2个过滤器,例如/ Jack / Accepted /,则会错误地捕获过滤器。
But if I only select 2 filters like /Jack/Accepted/ it grabs the filters incorrectly.
有没有一种方法可以实现这个?或我可以使用其他方法代替此方法。 Ty
Is there a way I can achieve this? Or some other method I can use instead of this. Ty
推荐答案
请勿尝试使用网址参数来执行此操作。而是使用querystring参数。 URL的格式应为:
Don't try and do this with URL arguments. Instead, use querystring arguments. The URL should be in the form:
my_path/?date=May&owner=Jack&category=Gas&status=accepted
,URL模式就是:
url(r'^my_path/$', views.my_view, 'my_url'),
,在视图中,您可以访问 request.GET ['date']
等。
and in the view you can access request.GET['date']
etc.
这篇关于具有多个可选参数的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!