【问题标题】:Flask Templates and Datatables - Responsive tables not loading correctlyFlask 模板和数据表 - 响应式表未正确加载
【发布时间】:2015-11-05 20:05:10
【问题描述】:

我正在使用 Flask 构建一个网络应用程序。我有base.html,它是带有导航栏和其他一些东西的父模板,然后从侧边栏加载的每个页面都使用扩展模板。当我将 datatables 表放在子模板中时,该表无法正确加载。我没有得到显示多少个整体的下拉列表,没有搜索功能等......我在这里做错了什么?

BASE.HTML

<!DOCTYPE html>
<html>
    <head>

    <!-- Bootstrap Core CSS -->
    <link href="static/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="static/metisMenu/dist/metisMenu.min.css" rel="stylesheet">

    <!-- Timeline CSS -->
    <link href="static/css/timeline.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="static/css/sb-admin-2.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="static/morrisjs/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="static/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- DataTables CSS -->
    <link href="static/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="static/datatables-responsive/css/dataTables.responsive.css" rel="stylesheet">


    </head>
    <body>

<----- BODY STUFF ----->
{% block content %} {% endblock %}

   <!-- jQuery -->
    <script src="{{ url_for('static', filename='jquery/dist/jquery.min.js') }}"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="{{ url_for('static', filename='bootstrap/dist/js/bootstrap.min.js') }}"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="{{ url_for('static', filename='metisMenu/dist/metisMenu.min.js') }}"></script>

    <!-- Morris Charts JavaScript -->
    <script src="{{ url_for('static', filename='raphael/raphael-min.js') }}"></script>
    <script src="{{ url_for('static', filename='morrisjs/morris.min.js') }}"></script>
    <script src="{{ url_for('static', filename='morris-data.js') }}"></script>

    <!-- Custom Theme JavaScript -->
    <script src="{{ url_for('static', filename='js/sb-admin-2.js') }}"></script>

    </body>
</html>

SETUP.HTML

{% extends "base.html"%}
{% block content %}

    <h1>Admin page</h1><hr> 

    {% if devices %}
    <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Devices
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>Device</th>
                                            <th>Type</th>
                                            <th>Location</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for device in devices %}
                                        <tr class="odd gradeX">
                                            <td>{{device.name}}</td>
                                            <td>{{device.type.name}}</td>
                                            <td>{{device.location.name}}</td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                                    <p><a href="{{ url_for('editDevices') }}"> Edit Devices </a></p>
                            </div>
                            <!-- /.table-responsive -->

                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
    {% endif %}


    <!-- DataTables JavaScript -->
    <script src="{{ url_for('static', filename='datatables/media/js/jquery.dataTables.min.js') }}"></script>
    <script src="{{ url_for('static', filename='datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js') }}"></script>


<script>
  $(function () {
    $("#example1").DataTable();
    $('#dataTables-example').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false
    });
  });
</script>

{% endblock %}    

【问题讨论】:

    标签: javascript python html flask datatables


    【解决方案1】:

    看起来您没有将块放入基础模板中。

    &lt;----- BODY STUFF -----&gt; 替换为{% block content %}{% endblock %}

    【讨论】:

    • 啊,看来我只是忘了把它放在密码框中。但是 {% block content %} 在正文中。
    猜你喜欢
    • 2023-03-12
    • 2015-04-09
    • 1970-01-01
    • 2011-10-24
    • 2019-05-13
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多