ipe*_*cks 3 python jinja2 flask twitter-bootstrap-3
目前,我正在处理Web应用程序的历史记录页面。应用程序(在Flask上编写)将历史记录保存在sqlite中,并通过SQLAlchemy与db一起使用。它看起来如下:
如您在最新单元格中看到的,有很多文本数据。
更重要的是,我想在历史页面上列出此数据。现在,我的代码如下所示:
{% extends "_base.html" %}
{% block content %}
<div id="div1" class="col-md-3">
<p><a href='/' class='btn btn-primary btn-block' role='button'><span class='glyphicon glyphicon-chevron-left'></span> Back</a></p>
</div>
<div class="bs-example col-md-12">
<br>
<table class="table table-hover">
<thead>
<tr>
<th>Task ID</th>
<th>Date</th>
<th>Host</th>
<th>User</th>
<th>Playbook</th>
<th>Log</th>
</tr>
</thead>
<tbody>
{% for history in histories %}
<tr>
<td>{{ history.task_id }}</td>
<td>{{ history.date.strftime("%d/%m/%y %H:%M") }} UTC</td>
<td>{{ history.hostname }}</td>
<td>{{ history.username }}</td>
<td>{{ history.playbook }}</td>
<td>{{ history.output }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
它产生这样的视图:
显然,它看起来很丑陋,所以我决定通过带有引导程序模块窗口的按钮隐藏此输出(最新单元格),就像这样
在这一点上,我有一个问题。我创建了下一个模板:
{% extends "_base.html" %}
{% block content %}
<div id="div1" class="col-md-3">
<p><a href='/' class='btn btn-primary btn-block' role='button'><span class='glyphicon glyphicon-chevron-left'></span> Back</a></p>
</div>
<div class="bs-example col-md-12">
<br>
<table class="table table-hover">
<thead>
<tr>
<th>Task ID</th>
<th>Date</th>
<th>Host</th>
<th>User</th>
<th>Playbook</th>
<th>Log</th>
</tr>
</thead>
<tbody>
{% for history in histories %}
<tr>
<td>{{ history.task_id }}</td>
<td>{{ history.date.strftime("%d/%m/%y %H:%M") }} UTC</td>
<td>{{ history.hostname }}</td>
<td>{{ history.username }}</td>
<td>{{ history.playbook }}</td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myOutput">Output</button></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Modal -->
<div class="modal fade" id="myOutput" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何为每个模态窗口的主体添加正确的输出。我是否需要使用不同的ID(如<div class="modal fade" id="myOutput1" role="dialog">
,<div class="modal fade" id="myOutput2" role="dialog">
等等)在代码中生成大量模态窗口?正确吗?
我已经用下一个代码完成了:
{% extends "_base.html" %}
{% block content %}
<div id="div1" class="col-md-3">
<p><a href='/' class='btn btn-primary btn-block' role='button'><span class='glyphicon glyphicon-chevron-left'></span> Back</a></p>
</div>
<div class="bs-example col-md-12">
<br>
<table class="table table-hover">
<thead>
<tr>
<th>Task ID</th>
<th>Date</th>
<th>Host</th>
<th>User</th>
<th>Playbook</th>
<th>Log</th>
</tr>
</thead>
<tbody>
{% for history in histories %}
<tr>
<td>{{ history.task_id }}</td>
<td>{{ history.date.strftime("%d/%m/%y %H:%M") }} UTC</td>
<td>{{ history.hostname }}</td>
<td>{{ history.username }}</td>
<td>{{ history.playbook }}</td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myOutput{{ history.task_id }}">Output</button></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% for history in histories %}
<!-- Modal -->
<div class="modal fade" id="myOutput{{ history.task_id }}" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Task Output</h4>
</div>
<div class="modal-body">
<p>{{ history.output }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
data-target
在按钮和id
在模态窗口是基于动态生成的task_id
值。我不知道这是否是最好的方法,但至少可以奏效。
归档时间: |
|
查看次数: |
7706 次 |
最近记录: |