Take the 2-minute tour ×

Here's my code in url.py:


I'd like to pass (?P<tag>\w+) to "tag_name" filter, but I don't know how to do it.

Also how can I pass multiple tags? Like this:


url.py should get "tag1+tag2+tag3", split it into "tag1", "tag2" and "tag3", and then put them in "tag__name__in":

queryset=List.objects.filter(tag__name__in=[tag1, tag2, tag3])

Basically I'm confused by the class-based generic view. Any idea?

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

You can overwrite the view's get_queryset method and construct a queryset with your results, eg.

from django.views.generic.list import ListView

class MyList(ListView):
    def get_queryset(self):
        tag_list = self.kwargs['tags'].split('+')
        return List.objects.filter(tag__name__in=tag_list)

# urls.py
url(r'tag/(?<tags>[\w\+]+)/', MyList.as_view())
share|improve this answer
It worked! Wow!!! Thanks! –  danielfeng May 29 '11 at 5:19
add comment

Your Answer


