@register.inclusion_tag(u'includes/pagination.html', takes_context=True)
def pagination_for(context, current_page, page_var=u'page', exclude_vars=u''):
 querystring = context[u'request'].GET.copy()
 exclude_vars = ([v for v in exclude_vars.split(u',') if v] + [page_var])
 for exclude_var in exclude_vars:
  if (exclude_var in querystring):
   del querystring[exclude_var]
 querystring = querystring.urlencode()
 return {u'current_page': current_page, u'querystring': querystring, u'page_var': page_var}

@ register . inclusion_tag ( u'includes/pagination.html' , takes_context = True ) def pagination_for ( context , current_page , page_var = u'page' , exclude_vars = u'' ) : querystring = context [ u'request' ] . GET . copy ( ) exclude_vars = ( [ v for v in exclude_vars . split ( u',' ) if v ] + [ page_var ] ) for exclude_var in exclude_vars : if ( exclude_var in querystring ) : del querystring [ exclude_var ] querystring = querystring . urlencode ( ) return { u'current_page' : current_page , u'querystring' : querystring , u'page_var' : page_var }
include the pagination template and data for persisting querystring in pagination links .