【问题标题】:"No matching records found" when using bootstrap-table in Flask在 Flask 中使用引导表时“找不到匹配的记录”
【发布时间】:2015-01-08 19:34:21
【问题描述】:

我现在正在开发基于flask 的网站,我想使用bootstrap-table 加载一个data.json。但我只得到了没有数据的表格。

目录结构如下图:

index.py
templates/
    new.html
    data.json
    data1.json
static/
    css/
        bootstrap-table.css
        bootstrap-theme.css     
        bootstrap-theme.min.css 
        bootstrap.css.map
        base.css               
        bootstrap-table.min.css 
        bootstrap-theme.css.map 
        bootstrap.css          
        bootstrap.min.css
    js/
        bootstrap-table.js     
        bootstrap.js           
        bower_components/     
        jquery.min.js
        bootstrap-table.min.js 
        bootstrap.min.js       
        index.js               
        npm.js

index.py 看起来像这样:

62 @app.route("/")
63 def new():
64     return render_template('new.html')

“新 .html”看起来像这样:

<!doctype html>
{% extends 'base.html' %}
{% block title %}Config{% endblock %}
{% block head %}
{{ super() }}
<!--<script type="text/javascript" src='../static/js/index.js'></script> -->
{% endblock %}
{% block header %}
    <p class="title">test</p>
{% endblock %}
{% block content %}
<table data-toggle="table" data-url="data1.json" data-cache="false" data-height="299">
<thead>
    <tr>
        <th data-field="id">Item ID</th>
        <th data-field="name">Item Name</th>
        <th data-field="price">Item Price</th>
    </tr>
</thead>
</table>
{% endblock %}

我已经链接了 base.html 中所需的所有 css 和 js 文件

但是当 index.py 运行时,我得到的页面如下。只显示表格,不显示数据

有人遇到过这个问题吗?

【问题讨论】:

  • 你能告诉我们你用来加载数据的代码吗?
  • @dazedconfused 根据bootstrap-table上的例子,我认为在html中设置'data-url=data1.json'时可以加载数据。是不是错了?
  • 似乎是正确的;你的data1.json 是什么样的?它是否包含idnameprice 作为其字段?另外,我发现您的new.html 中没有包含jquerybootstrapbootstrap-table;见Usage
  • @dazedconfused data1.json 与example on official website 相同,并且我已链接 base.html 中的所有文件。如表所示,css 工作没有问题,但只有数据丢失。

标签: python html json twitter-bootstrap flask


【解决方案1】:

首先,对于 Flask,确保 json 文件位于 static 文件夹中。太琐碎了,我试了很多次才弄明白。

然后,确保包含 json 数组的 json 文件的格式正确。

FYR Bootstrap table showing JSON data

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多