Fomalhaut
Fomalhaut

Reputation: 9765

How to access to URL parameter inside of get_queryset in Django?

Supposing, I've got a URL pattern like this:

urlpatterns = [
    ...
    url(r'^mylist/(?P<offset>\d+)/$', MylistView.as_view(), name='mylist'),
    ...
]

My view class:

class MylistView(ListView):
    template_name = 'mylist.html'

    def get_queryset(self, *args, **kwargs):
        offset = ... # What should I type here?
        entries = models.MylistEntry.all()[offset:offset+10]
        return entries

How do I access to the URL parameter offset within the method get_queryset? I've checked the variables args and kwargs are empty.

Thanks for advance!

Upvotes: 7

Views: 2052

Answers (1)

Neeraj Kumar
Neeraj Kumar

Reputation: 3941

Use self of get_queryset method for fetch url parameter

 self.kwargs.get('offset')

Upvotes: 14

Related Questions