Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep query parameters during pagination with webhelpers.paginate
    text
    copied!<p>I look an example of paginating from <a href="http://rapidprototype.ch/bg2docs/tg2pagination.html" rel="nofollow noreferrer">http://rapidprototype.ch/bg2docs/tg2pagination.html</a> for my Turbogears 2 project and it works great but, I have a problem regarding my query parameters when I change the page I'm looking.</p> <p>This is what I have in my controller when listing.</p> <pre><code>def list(self, page=1, **kw): q = "" if kw.has_key('q'): log.debug("searching %s" % kw) q = kw['q'] if kw.has_key('all'): q = "" products = DBSession.query(model.Product).filter( or_(model.Product.name.like('%%%s%%' % q), model.Product.description.like('%%%s%%' % q), model.Product.model.like('%%%s%%' % q), model.Product.code.like('%%%s%%' % q))).all() def get_link(product): return Markup("""&lt;a href="form?id=%s"&gt;%s&lt;/a&gt;""" % (product.id, product.id)) product_fields = [ (Markup("""&lt;a href="?s=id"&gt;Id&lt;/a&gt;"""), get_link), (u'Name', 'name'), (u'Model', 'model'), (u'Code', 'code'), (u'Description', 'description')] product_grid = MyDataGrid(fields = product_fields) currentPage = paginate.Page(products, page, items_per_page=50) return dict(currentPage=currentPage, title=u'Products List', item=u'product', items=u'products', data=currentPage.items, grid=product_grid, page=u'Search %s results' % q, q=q, hits=len(products)) </code></pre> <p>This is the html template fragment</p> <pre><code>&lt;h1&gt;List of ${items}&lt;/h1&gt; &lt;form action="list" method="get"&gt; &lt;input name="q" type="text" value="${value_of('q', default='')}"/&gt; &lt;input type="submit" value="Search"/&gt; &lt;input type="submit" name="all" value="All"/&gt; &lt;/form&gt; ${hits} ${items} found &lt;p class="pagelist"&gt;${currentPage.pager(format='$link_first ~3~ $link_last')}&lt;/p&gt; &lt;div&gt; ${grid(data)} &lt;/div&gt; &lt;p&gt;&lt;a href="${tg.url('form')}"&gt;Add a ${item}&lt;/a&gt;&lt;/p&gt; </code></pre> <p>The searches works fine resulting in links like this '<em>/list?q=cable</em>' but when I click some of the paginating pages "1,2...8,9" turns to '<em>/list?page=2</em>'</p> <p>How do I add my previous query parameter or any other parameters to the link?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload