python – Flask pagination without sqlAlchemy


I have a Flask application using a MySQL database. Raw MySQL queries. There is a page on which news are displayed. I want to do something like pagination or a button for dynamic loading, "Show more". If something is not clear written, do not get angry.
def index():
    return render_template('index.html', menu=dbase.getMenu(), posts=dbase.getPostAnonce())

class SqlCon():
    def __init__(self, bd):
        self.__bd = bd
        self.__cur =bd.cursor()
    def getPostAnonce(self):
            sql = "SELECT id, title, posttext, url, `data` FROM z250wzqrec95yxzh.postnews ORDER BY `data` 
         DESC "
            res = self.__cur.fetchall()
            if res: return res
        except pymysql.Error as e:
            print('Ошибка работы с таблицей sqlsite.postnews метод getPostAnonce'+str(e))
            return False
        return []


{% extends 'base.html' %}
{% block content %}
{{ super() }}

<h2>Новости охотничьего мира России</h2>
{% for p in posts %}
<div class="card">
  <div class="card-header">
   Дата: {{'%d-%m-%Y') }}
  <div class="card-body">
    <h5 class="card-title">{{ p.title }}</h5>
    <p class="card-text">{{ p.posttext[:100]|striptags}}</p>
    <a href="{{url_for('showPost', allias=p.url)}}" class="btn btn-success">Читать новость</a>
{% endfor %}

{% endblock content %}
{% block footer %}
{% endblock %}


You can use url_for. In order to create a hyperlink to an object located in your project.

Scroll to Top