Python 与烧瓶配合使用

Python 与烧瓶配合使用,python,angularjs,flask,Python,Angularjs,Flask,我有一个excel文件,我正在使用Flask将其作为表格放入html中。以下是代码: filename = 'abc.xlsx' data = pd.read_excel(filename,sheetname='Add-on') data = data.fillna('') return render_template('index.html',tables=[data.to_html()], titles = ['Excel Data to Flask']) 现在,我想使用angular在h

我有一个excel文件,我正在使用Flask将其作为表格放入html中。以下是代码:

filename = 'abc.xlsx'
data = pd.read_excel(filename,sheetname='Add-on')
data = data.fillna('')
return render_template('index.html',tables=[data.to_html()],
titles = ['Excel Data to Flask'])
现在,我想使用angular在html中添加一些控制器。但问题是pandas
to_html
函数已经创建了一个表结构

这是我的index.html模板

<div class="container" data-ng-app="myApp" data-ng-controller="myCtrl">
<div class="row">
 <div class="col-md-2">
    Search:
 </div>
 <div class="col-md-10">
    <input type="text" class="search" data-ng-model="table" />
  </div>
</div>
<br/>
<div class=page>
<!-- <h1>Python</h1> -->
{% for table in tables %}
<h2>{{titles[loop.index]}}</h2>
{{ table|safe }}
{% endfor %}
</div>
</div>
<div data-pagination="" data-num-pages="numPages()" data-current- 
page="currentPage" data-max-size="maxSize" data-boundary-links="true"></div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js" />
<script>
var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myCtrl', function($scope) {
$scope.currentPage = 1,
$scope.numPerPage = 5,
$scope.maxSize = 5;
$scope.numPages = function () {
return Math.ceil($scope.customers.length / $scope.numPerPage);
};
$scope.$watch('currentPage + numPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
 });
 });
 </script>

搜索:

{对于表%%中的表,%} {{titles[loop.index]} {{表|安全}} {%endfor%} var-app=angular.module('myApp',['ui.bootstrap']); 应用程序控制器('myCtrl',函数($scope){ $scope.currentPage=1, $scope.numPerPage=5, $scope.maxSize=5; $scope.numPages=函数(){ 返回Math.ceil($scope.customers.length/$scope.numPerPage); }; $scope.$watch('currentPage+numPerPage',function(){ var begin=($scope.currentPage-1)*$scope.numPerPage) ,end=begin+$scope.numPerPage; }); });
但这不起作用,我应该能看到页码,但我看不到。也,
如何在html的tr标记中插入
data ng repeat=“customer in people | filter:table”
,以搜索html表。因为pandas
to_html()
会自动为我创建模板。

而不是从python传递完整的表。以这种形式传递数组。基本上是数组中的dictionary对象

    People=[
    {name:'abc',phone:1234,age:18},
    {name:'abc1',phone:12346,age:18},
    {name:'abc1',phone:1234,age:18},
    {name:'abc1',phone:12345,age:18},
    ]
now in your tr tag
<tr ng-repeat="customer in people">
<td>{{customer.name}}</td>
<td>{{customer.phone}}</td>
<td>{{customer.age}}</td>
人=[
{姓名:'abc',电话:1234,年龄:18},
{姓名:'abc1',电话:12346,年龄:18},
{姓名:'abc1',电话:1234,年龄:18},
{姓名:'abc1',电话:12345,年龄:18},
]
现在在您的tr标签中
{{customer.name}
{{customer.phone}}
{{customer.age}
这是从python执行此操作的标准方法。可以使用flask.jsonify()返回数据