title: Flask pagination combined with query
body: <p>I'm currently trying to build a small flask app in python which takes in a csv via pandas and paginates the results. I've already finished the process of importing the dataset with pandas, converting it to a list of dictionaries and paginating the results into a table using flask_paginate. </p>
  
  <p>Now, I'd like to extend this code to allow querying of terms in the dataset for example (show and paginate all results where 'Customer Name' contains 'Barry'). I'm aware ill need to use an input box and process a post request but I am very unsure of how to wire it all together in the index route.</p>
  
  <p>Any help would be greatly appreciated thanks.</p>
  
  <p>Code for app.py</p>
  
  <pre><code>from flask import Flask, render_template
  from flask_paginate import Pagination, get_page_args
  import pandas
  
  app = Flask(__name__)
  app.debug = True
  
  df = pandas.read_csv('static/superstore.csv')
  data = df.to_dict(orient = 'records')
  
  def get_users(offset=0, per_page=20):
  
      return data[offset: offset + per_page]
  
  @app.route('/')
  def index():
  
      page, per_page, offset = get_page_args(page_parameter='page', per_page_parameter='per_page')
  
      total = len(data)
  
      pagination_users = get_users(offset=offset, per_page=per_page)
  
      pagination = Pagination(page=page, 
                              per_page=per_page, 
                              total=total,
                              css_framework='bootstrap4')
  
      return render_template('index.html',
                             data=pagination_users,
                             page=page,
                             per_page=per_page,
                             pagination=pagination)
  </code></pre>
  
  <p>Code for index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
      &lt;title&gt;flask-bootstrap example&lt;/title&gt;
      &lt;!-- Bootstrap --&gt;
      &lt;!-- Latest compiled and minified CSS --&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"&gt;
  
      &lt;link rel="stylesheet" type="text/css" href="static/main.css"&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class = "bg-primary"&gt;
      &lt;div class = "container jumbotron jumbotron-fluid bg-transparent text-white"&gt;
        &lt;h1 class = "display-4"&gt;Pagination Example&lt;/h1&gt;
  
      &lt;/div&gt;
    &lt;/div&gt;
      &lt;div class="container"&gt;
        &lt;div class="table-responsive"&gt;
          &lt;table class="table table-hover"&gt;
            &lt;thead&gt;
              &lt;tr&gt;
                &lt;th&gt;Order ID&lt;/th&gt;
                &lt;th&gt;Order Date&lt;/th&gt;
                &lt;th&gt;Profit&lt;/th&gt;
                &lt;th&gt;Unit Price&lt;/th&gt;
                &lt;th&gt;Order Quantity&lt;/th&gt;
                &lt;th&gt;Customer Name&lt;/th&gt;
                &lt;th&gt;Region&lt;/th&gt;
              &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
              {% for item in data %}
              &lt;tr&gt;
                &lt;td&gt;{{ item['Order ID'] }}&lt;/td&gt;
                &lt;td&gt;{{ item['Order Date'] }}&lt;/td&gt;
                {%if item['Profit'] &gt; 0%}
                  &lt;td&gt;&lt;span class ="badge badge-success"&gt;{{ item['Profit'] }}&lt;/span&gt;&lt;/td&gt;
                {%else%}
                  &lt;td&gt;&lt;span class ="badge badge-danger"&gt;{{ item['Profit'] }}&lt;/span&gt;&lt;/td&gt;
                {%endif%}
  
                &lt;td&gt;{{ item['Unit Price'] }}&lt;/td&gt;
                &lt;td&gt;{{ item['Order Quantity'] }}&lt;/td&gt;
                &lt;td&gt;{{ item['Customer Name'] }}&lt;/td&gt;
                &lt;td&gt;{{ item['Region'] }}&lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
            &lt;/tbody&gt;
          &lt;/table&gt;
        &lt;/div&gt;
        {{ pagination.links }}
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Screenshot:
  <a href="https://i.stack.imgur.com/B4os5.png" rel="nofollow noreferrer">Screenshot of localhost:5000/</a></p>