标签:代码 导入 return models name his url int link
flask_sqlalchemy对象提供分页方法
from models import <table_name> #导入model的对象 @app.route(‘/‘, methods=[‘GET‘, ‘POST‘]) @app.route(‘/<int:page>‘, methods=[‘GET‘, ‘POST‘]) def index(page=1): pagination = <table_name>.query.paginate(page, 20, False) #flask_sqlalchemy提供分页方法.paginate db.session.close() return render_template(‘index.html‘, pagination=pagination)
<div class="pagination"> <ul class="pagination"> {% for page in pagination.iter_pages() %} <li> <a class="page-link3" href="{{ url_for(‘index‘, page=page) }}">{{ page }}</a> </li> {% endfor %} </ul> </div>
$(document).on(‘click‘, ‘.page-link3‘, function(event) { var link = $(this).attr(‘href‘); $.ajax({ type:‘POST‘, url:link, success:function(data){ $("body").html(data); } }); event.preventDefault(); }); });
Flask 分页的简单用法 / flask_sqlalchemy /无刷新翻转页面(原创)
标签:代码 导入 return models name his url int link
原文地址:https://www.cnblogs.com/kiddy/p/9829464.html