Next and Before Links for a django paginated query

前端 未结 4 777
小蘑菇
小蘑菇 2021-01-07 06:07

I\'m trying to make a search form for Django.

Its a typical search form and then returns a table of matches. I wish to paginate the tables returned.

The prob

4条回答
  •  忘掉有多难
    2021-01-07 07:03

    I would recommend putting the solution in a template tag like so:

    myapp/templatetags/mytemplatetags.py:

    from django import template
    register = template.Library()
    
    @register.simple_tag
    def url_replace(request, field, value):
        d = request.GET.copy()
        d[field] = value
        return d.urlencode()
    
    @register.simple_tag
    def url_delete(request, field):
        d = request.GET.copy()
        del d[field]
        return d.urlencode()
    

    Then from templates do:

    {% load mytemplatetags %}
    ...
    previous
    

提交回复
热议问题