【发布时间】:2018-09-08 12:56:53
【问题描述】:
所以我使用 Flask 作为微框架,并在我的一个模板中使用下表:
<table id = "productentabel" width = "auto" class="table table-striped b-t b-b">
<thead>
<tr class = "header">
<th>Name</th>
<th>Url</th>
</thead>
{% for file in all_files['files'] %}
{% if file['mimeType'] == 'application/vnd.google-apps.document' %}
<TR>
<TD width="auto" >{{file['name']}}</TD>
<td><a class="btn btn-xs white" href = "https://docs.google.com/document/d/{{file['id']}}" target ="_blank">Go to file</a></td>
<td><form method=POST action="delete_file"><input type=submit name="delete" value ="{{file['id']}}" class="btn btn-xs white">Delete file</input>
</form></td>
</TR>
{% endif %}
{% endfor %}
</tr>
</table>
我的问题是关于以下 HTML 代码:
<form method=POST action="delete_file"><input type=submit name="delete" value ="{{file['id']}}" class="btn btn-xs white">Delete file</input>
</form>
如您所见,当单击输入时,我试图将值传递给我的 Python 代码。该值被传递给我的 Python 代码,但现在该值在前端可见,所以它看起来像这样:
1svpTERHaYd-wSpFBRRRjp1TOj0H-FH4_66H2W1OLY 删除文件
但我希望它是这样的:
删除文件
在 Python 中,我正在执行以下操作来提取值:
fileid = request.form.get('delete')
我也试过这样的:
<form method=POST action="delete_file"><input type=submit name="{{file['id']" class="btn btn-xs white">Delete file</input>
</form>
但是我真的不知道如何在我的 Python 代码中提取名称,因为我只需要传递 file['id'] 并且值解决方案对我有用,但这不是理想的解决方案。
【问题讨论】:
-
顺便说一句.. 我认为,您的表结构中有错误。您还没有关闭
<thead>中的<tr>标签。 -
@Arihant,它在循环后错误地关闭了。虽然标记无效,但大多数浏览器会在遇到
</thead>标签时自动关闭它,并在以后遇到它时忽略关闭标签。不过我不是 100% 确定,这绝对是应该解决的问题。 -
@Arihant 啊,我明白了,谢谢。
-
@AndreiGheorghiu 我想也许使用 CSS 也是一种解决方法。但我删除了标签:)