models.py:
admin.py:
views.py:
其中all函数是关键。
index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% load staticfiles %}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="{% static ‘libs/bootstrap/css/bootstrap.min.css‘ %}">
<link rel="stylesheet" href="{% static ‘libs/toastr/css/toastr.css‘ %}">
<link rel="stylesheet" href="{% static ‘libs/bootstrap-table-master/bootstrap-table.css‘ %}">
<script src="{% static ‘libs/jquery/jquery-1.11.2.min.js‘ %}"></script>
<script src="{% static ‘libs/bootstrap/js/bootstrap.min.js‘ %}"></script>
<script src="{% static ‘libs/toastr/js/toastr.min.js‘ %}"></script>
<script src="{% static ‘libs/bootstrap-table-master/bootstrap-table.js‘ %}"></script>
<script src="{% static ‘libs/bootstrap-table-master/locale/bootstrap-table-zh-CN.js‘ %}"></script>
<title>Django后台管理系统</title>
</head>
<body>
<div style="padding: 20px;">
<table id="articles-table" data-toggle="table" class="table table-bordered table-striped"></table>
</div>
<script>
var $articlesTable = $(‘#articles-table‘).bootstrapTable(‘destroy‘).bootstrapTable({
url: ‘/article/all/‘,
method: ‘GET‘,
dataType: "json",
uniqueId: ‘id‘,
striped: false,
cache: false,
sortName: ‘id‘,
sortable: false,
sortOrder: ‘desc‘,
sidePagination: "server",
undefinedText: ‘--‘,
singleSelect: false,
toolbar: ‘#soft-toolbar‘,
search: false,
strictSearch: true,
clickToSelect: true,
pagination: true,
pageNumber: 1,
pageSize: 5,
pageList: [5, 10, 20, 50, 100],
paginationPreText: "上一页",
paginationNextText: "下一页",
queryParamsType: "",
queryParams : function (params) {
var temp = {
‘pageSize‘ : params.pageSize,
‘pageNumber‘ : params.pageNumber,
‘searchText‘: params.searchText,
‘sortName‘: params.sortName,
‘sortOrder‘: params.sortOrder
};
return temp;
},
columns: [
{
checkbox: true
},{
field: ‘title‘,
title:‘标题‘,
width: ‘12%‘
},{
field: ‘content‘,
title:‘内容‘,
width: ‘62%‘
},{
field: ‘create_time‘,
title:‘创建时间‘,
width: ‘10%‘
},{
title:‘删除‘,
formatter: function(value, row, index){
return ‘<button type="button" class="btn btn-primary btn-xs" onclick="deleteData(‘ + row.id + ‘)">删除</button>‘;
}
}
],
onLoadError: function () {
toastr.error("数据加载失败!", "错误提示");
},
onClickRow: function (row, $element) {

以上四个文件中,views.py和index.html文件是关键。
Django+BootstrapTable实现表格分页
原文:https://www.cnblogs.com/samve/p/11273288.html