Fomalhaut Fomalhaut - 1 year ago 81
Python Question

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!

Answer Source

Use self of get_queryset method for fetch url parameter

 self.kwargs.get('offset')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download