python – django filters with pagination: showing same page after pressing next url

When i search for something(like tom), it works well for first page. But if I click next page url, it shows the same result, nothing changes, but in url, it becomes to

class VideoFilter(django_filters.FilterSet):
    class Meta:
        model = Video
        fields = ['caption']
        filter_overrides = {
             models.CharField: {
                 'filter_class': django_filters.CharFilter,
                 'extra': lambda f: {
                     'lookup_expr': 'icontains',

def search(request):
    queryset = Video.objects.all()
    filterset = VideoFilter(request.GET, queryset=queryset)
    if filterset.is_valid():
        queryset = filterset.qs

    paginator = Paginator(queryset, 2)
    page_number = request.GET.get('page')
    print(page_number)# always prints **none**
    queryset = paginator.get_page(page_number)
    return render(request, 'search.html',{
        'result': queryset,
        'caption': request.GET['caption'],


{% extends 'navbar.html' %}
{% block body %}

<!-- more code -->
{% if result.has_next %}
    <a href="?caption={{caption}}&?page={{result.next_page_number}}"><button>See more results</button></a>
{% endif %}

{% endblock body %}


<!-- more code -->
<form action="/search/" method="GET"> <!-- working without csrf_token -->
            <input type="text" placeholder="Search" id="search" name="caption" required />
            <button type="submit">Search</button>

where is the problem?
how do i visit next page?

Product of the Month September 2016

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *