Python flask 实现分页显示MySQL数据前端代码
时间: 2024-05-05 13:18:48 浏览: 163
python flask实现分页效果
很高兴回答你的问题!以下是Python Flask实现分页显示MySQL数据的前端代码:
```html
{% extends 'base.html' %}
{% block content %}
<div class="container">
<h1>MySQL Data</h1>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Age</th>
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td>{{ row.email }}</td>
<td>{{ row.age }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<nav aria-label="Page navigation">
<ul class="pagination">
{% if page == 1 %}
<li class="disabled">
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
{% else %}
<li>
<a href="{{ url_for('index', page=page-1) }}" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
{% endif %}
{% for n in range(1, pages+1) %}
{% if n == page %}
<li class="active">
<a href="#">{{ n }}</a>
</li>
{% else %}
<li>
<a href="{{ url_for('index', page=n) }}">{{ n }}</a>
</li>
{% endif %}
{% endfor %}
{% if page == pages %}
<li class="disabled">
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
{% else %}
<li>
<a href="{{ url_for('index', page=page+1) }}" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
{% endif %}
</ul>
</nav>
</div>
{% endblock %}
```
希望这个答复能够帮到你!
阅读全文