繁体   English   中英

将数据从模板发送到烧瓶

[英]sending data from template to flask

我正在使用flask建立一个网站。 它在top.html中使用sql显示列表,其中每个元素都是超文本。

 <table class="table table-striped">
    <thead></thead>
  <tr>
    <th>Company</th>
  </tr></thead>
  <tbody>
        {% for company in companies %}
            <tr>
                <td><a href="{{ url_for('text') }}" method = "POST" name = "{{ company.name }}">{{ company.name }}</a></td>
            </tr>
        {% endfor %}
        </tbody>
</table>

因此,我想知道从列表中单击了哪个超文本,以便可以将其各自的内容加载到/ text中。 请同时提供python代码(烧瓶代码)。

首先为每个<a输入公司唯一标识符,例如<a data-id =“ 11” ...

然后像这样在每个<a上添加事件侦听器...

 var companyLinks = document.querySelectorAll('.table-striped a'); for (var i = 0; i < companyLinks.length; i += 1) { companyLinks[i].addEventListener('click', function (e) { // get the company id of clicked link var companyId = e.target.dataset.id; // now do what you like with the company id // for example you can send an AJAX call to your backend }); } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM