#!/usr/bin/python3 import sqlite3 from flask import Flask, request, render_template from flask import g from flask_paginate import Pagination, get_page_parameter DATABASE = "../data/diffs.db" app = Flask(__name__) def get_db(): db = getattr(g, '_database', None) if db is None: db = g._database = sqlite3.connect(DATABASE) db.row_factory = sqlite3.Row return db @app.teardown_appcontext def close_connection(exception): db = getattr(g, '_database', None) if db is not None: db.close() @app.route('/') def index(): db = get_db().cursor() db.execute('SELECT count(diff_id) FROM diffs') diff_count = db.fetchall()[0][0] #flask-paginate page = request.args.get(get_page_parameter(), type=int, default=1) pagination = Pagination(page=page, total=diff_count, record_name='diffs') page_skip = pagination.skip per_page = pagination.per_page db.execute("SELECT * FROM diffs ORDER BY diff_id DESC LIMIT ? OFFSET ?", (per_page,page_skip)) diffs = db.fetchall() return render_template('./index.html', diffs=diffs, pagination=pagination, ) if __name__ == "__main__": app.run(host="0.0.0.0")