how to design URL pattern to get the field value using request.query_params.get in the view

22 views
Skip to first unread message

Afiz S

unread,
Sep 4, 2016, 11:00:36 AM9/4/16
to Django users
Hi All, 

I have very new to Django. Can anyone tell me how to the data from URL to view.

in this below example I am trying to get year param from the URL. 

def get_queryset(self):
queryset = Battles.objects.all()
year = self.request.query_params.get('year',None)
if year is not None:
queryset = queryset.filter(year__exact=year)
return queryset

ADEWALE ADISA

unread,
Sep 4, 2016, 4:31:51 PM9/4/16
to django...@googlegroups.com

show your url configuration

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/693bbae5-0ffc-4737-86be-a9cee202e68e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Siddharth Ghumre

unread,
Sep 5, 2016, 9:06:41 AM9/5/16
to django...@googlegroups.com
If I understand it correctly, for this view your url must correspond to 


Here as per standard url protocol, anything you pass after the "?" (question mark) is passed as a request.query_params to the views.

Hope this helps.
Sid


--
Reply all
Reply to author
Forward
0 new messages