Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url with multiple optional arguments

Tags:

django

right now I have a view to show info about some tickets and I'm trying to add a functionality to filter those tickets.

Say I will have 4 filters:

  • Date
  • Owner
  • Category
  • Status

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

But if I only select 2 filters like /Jack/Accepted/ it grabs the filters incorrectly.

Is there a way I can achieve this? Or some other method I can use instead of this. Ty

like image 367
Jay Avatar asked Jul 15 '26 23:07

Jay


1 Answers

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

and the URL pattern is just:

url(r'^my_path/$', views.my_view, 'my_url'),

and in the view you can access request.GET['date'] etc.

like image 194
Daniel Roseman Avatar answered Jul 19 '26 02:07

Daniel Roseman