If I understand it correctly, for this view your url must correspond to

http://www.mysite.com/xyz?year=2015

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


On Sun, Sep 4, 2016 at 10:03 PM, Afiz S <afi...@gmail.com> wrote:

> 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
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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
> <https://groups.google.com/d/msgid/django-users/693bbae5-0ffc-4737-86be-a9cee202e68e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CANtEdp6n%2Bj5Gar-XVcEU%3DhRooy8nOCW_iMBBDCE_BM%2BnOkuDyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to