91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python flask 的分頁使用

發布時間:2020-06-21 00:18:41 來源:網絡 閱讀:1228 作者:ading2016 欄目:編程語言

1、views 如下示例代碼:

@admin.route("/account/list/<int:page>/",?methods=["GET"])
@admin_login_req
def?account_list(page=None):
????if?page?is?None:
????????page?=?1
????page_data?=?Account.query.order_by(
????????Account.name.desc()
????).paginate(page=page,?per_page=10)
????return?render_template('admin/account_list.html',?page_data=page_data)

2、模板 account_list.html

{%?extends?'admin/base.html'?%}
{%?import?"admin/ui/admin_page.html"?as?pg?%}

{%?block?css?%}

{%?endblock?%}
{%?block?content?%}

<div?class="panel?panel-default">
????<div?class="panel-heading">
????????查詢條件
????</div>
????<div?class='panel-body'>
????????<div?class="row">
????????????<form?role="form">
????????????????<div?class="col-sm-6?col-md-6?col-lg-4">
????????????????????<div?class="form-group">
????????????????????????<div?class="input-group">
????????????????????????????<div?class="input-group-addon">查找</div>
????????????????????????????<input?class="form-control"?type="email">
????????????????????????</div>
????????????????????</div>
????????????????</div>
????????????????<div?class="col-lg-12">
????????????????????<hr?class="mt5?mb15">
????????????????????<button?type="submit"?class="king-btn?king-info">查詢</button>
????????????????????<a?class="king-btn?king-success"?href="{{?url_for('admin.account_add')?}}">添加賬號</a>
????????????????</div>

????????????</form>
????????</div>
????</div>
</div>
<!---->
<div?class="panel?panel-default">
????<div?class="panel-heading">
????????帶邊框的表格
????</div>
????{%?for?msg?in?get_flashed_messages(category_filter=["ok"])?%}
????<div?class="king-notice2?king-notice-success?notice-borders">
????????<i?class="fa?fa-check-circle"></i>
????????<div?class="notice-text">
????????????<p>{{?msg?}}</p>
????????</div>
????</div>
????{%?endfor?%}
????<div?class='panel-body'>
????????<div?class="table-responsive">
????????????<table?class="table?table-bordered?table-hover?table-striped">
????????????????<thead>
????????????????<tr>
????????????????????<th>名稱</th>
????????????????????<th>網站/IP</th>
????????????????????<th>用戶名</th>
????????????????????<th>密碼</th>
????????????????????<th>備注</th>
????????????????????<th>操作</th>
????????????????</tr>
????????????????</thead>
????????????????<tbody>
????????????????{%?for?v?in?page_data.items?%}
????????????????<tr>
????????????????????<td>{{?v.name?}}</td>
????????????????????<td>{{?v.website?}}</td>
????????????????????<td>{{?v.username?}}</td>
????????????????????<td>{{?v.pwd?}}</td>
????????????????????<td>{{?v.comment?}}</td>
????????????????????<td>
????????????????????????<button?type="submit"?class="king-btn?king-warning">編輯</button>
????????????????????????<a?href="{{?url_for('admin.account_del',?id=v.id)?}}"?type="submit"
???????????????????????????class="king-btn?king-danger">刪除</a>
????????????????????</td>
????????????????</tr>
????????????????{%?endfor?%}
????????????????<tfoot>
????????????????<tr>
????????????????????<td?colspan="6">
????????????????????????<div?class="pagination-info?pull-left">共有{{?page_data.total?}}條,每頁顯示:{{?page_data.per_page?}}條
????????????????????????</div>
????????????????????????<div?class="pull-right?king-page-box">
????????????????????????????{{?pg.page(page_data,?'admin.account_list')?}}
????????????????????????</div>
????????????????????</td>
????????????????</tr>
????????????????</tfoot>
????????????????</tbody>
????????????</table>
????????</div>
????</div>
</div>

</div>
{%?endblock?%}

{%?block?js?%}

{%?endblock?%}

3、admin_page.html? 為分頁的模板

{%?macro?page(data,?url)?-%}
{%?if?data?%}
<ul?class="pagination?pagination-small?pull-right">
????<li><a?href="{{?url_for(url,?page=1)?}}">首頁</a></li>

????{%?if?data.has_prev?%}
????<li?class="active"><a?href="{{?url_for(url,?page=data.prev_num)?}}">上一頁</a></li>
????{%?else?%}
????<li?class="disabled"><a?href="#">上一頁</a></li>
????{%?endif?%}

????{%?for?v?in?data.iter_pages()?%}
????????{%?if?v?==?data.page?%}
????????<li?class="active"><a>{{?v?}}</a></li>
????????{%?else?%}
????????<li><a?href="{{?url_for(url,?page=v)?}}">{{?v?}}</a></li>
????????{%?endif?%}
????{%?endfor?%}

????{%?if?data.has_next?%}
????????<li?class="active"><a?href="{{?url_for(url,?page=data.next_num)?}}">下一頁</a></li>
????{%?else?%}
????????<li?class="disabled"><a?href="#">下一頁</a></li>
????{%?endif?%}

????<li><a?href="{{?url_for(url,?page=data.pages)?}}">尾頁</a></li>
</ul>
{%?endif?%}
{%-?endmacro?%}

flask-sqlalchemy 的分頁參考文檔 http://www.pythondoc.com/flask-sqlalchemy/api.html#id1

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宜阳县| 巢湖市| 沁源县| 遵化市| 乐东| 荆门市| 那坡县| 寻乌县| 常山县| 额济纳旗| 石棉县| 灵宝市| 富宁县| 中方县| 大田县| 邢台县| 海宁市| 美姑县| 彰武县| 宁津县| 玛多县| 隆尧县| 临安市| 云和县| 荣成市| 威海市| 怀远县| 泰州市| 历史| 仁布县| 德阳市| 泌阳县| 永修县| 墨玉县| 县级市| 班玛县| 江陵县| 高碑店市| 边坝县| 民权县| 陇川县|