我让烧瓶将数据发送到html。现在,它第一次通过render_template('page1.html', data=data)
进行操作,从而填充了主表。现在,当我单击主表的任何行时,我想再次通过url_for(entrypoint)
调用flask,然后再次为第二个表执行render_template('page1.html', data=data2)
。但是如何区分它们呢?我的意思是html如何知道哪些数据是为谁而来的?请指教。我是javascript和html的新手。我计划将主表和辅助表保留为不同的形式。请提供建议,以决定是否正确。
我在html(page1.html)里面写了
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function getId(element) {
var row_index=element.rowIndex;
$.ajax({
url: '/get_details',
data: document.getElementById("table1").rows[row_index].cells[5].innerHTML),
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
这是html中table1和table2的代码(table2尚未完成)
<section id="boxes" style="margin-top:-5%; margin-bottom:0%; position:absolute; z-index:1;">
<div class="box" style="margin-left:30px; margin-top:20px; z-index:1;">
<table id="table1">
<tr>
<th>NO</th>
<th> SUBJECT NAME</th>
<th>ASSIGNED TO</th>
<th>CREATED</th>
<th>DISEASES</th>
<th>SUBJECT ID</th>
<th>STATUS</th>
</tr>
{% for row in data %}
<tr onclick="getId(this)">
<td> {{ row[0] }}</td>
<td> {{ row[1] }}</td>
<td> {{ row[2] }}</td>
<td> {{ row[3] }}</td>
<td> {{ row[4] }}</td>
<td> {{ row[5] }}</td>
<td> {{ row[6] }}</td>
</tr>
{% endfor %}
</table>
</div>
<div class="box-two">
</div>
在我的app.py中 这是入口点的烧瓶代码:
@app.route('/get_details', methods=['POST'])
def get_details_user(patientid):
print(patientid)
这是到现在为止填充table1的记录的入口点的代码:
@app.route('/records')
@login_required
def records():
if current_user.priviledge:
data = get_records_by_userid(None)
else:
data = get_records_by_userid(current_user.id)
list_data = []
for row in data:
list_data.append([])
for col, val in row.items():
list_data[-1].append(val)
return render_template('records.html', data=list_data)
我的烧瓶代码没有被触发。我的ajax代码出了点问题??另外,如何将烧瓶中的数据获取到第二张表的相同html文件中?
非常感谢, Sudip
答案 0 :(得分:1)
更新:由于ajax函数语法而导致错误。在ajax ... oops中添加了额外的')'数据,那很糟糕
答案 1 :(得分:0)
将其添加到Java代码:
import pysftp
hostname = 's-ad7**********.server.transfer.us-east-1.amazonaws.com'
username = '***'
path = 'C:\\keys\\<your_private_key_file>.pem'
def sftptransfer():
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(hostname, username=username, private_key=path, cnopts=cnopts) as sftp:
sftp.put('<path of input file>', '<target directory path>') # target dirctory path is optional
sftp.close()
sftptransfer()
这是允许对AJac进行验证的令牌