WTForms只提交第一个表单

WTForms only submits first form

本文关键字:表单 第一个 提交 WTForms      更新时间:2023-09-26

我有一个博客页面,用户可以在其中添加回复,这很好。

我还有一个编辑功能,但它不起作用。只有第一个。

例如,当我提交第二个或第三个表格时,第一个表格总是被提交的。但当我提交第一份时,第二份就提交了。

以下是Jinja2 WTForms代码

{% for item in items %}    
<form method=post action="/reply/edit">      
  {{reply-form.content}}
  <input type=submit value="Submit">    
{% endfor %}

以下是当调用某个路由(/reply/edit)时执行的功能

def reply_edit():
    reply-form = Reply(request.forms)
    if reply-form.validate():
        content = reply-form.data['content']
        return content
    else:
        return 'houston, we have a problem'

基本上,当未展开时,表格是这样排列的

---------------------
|    first form     |
|                   |
---------------------
----------   --------
| delete |   | edit |
----------   --------
---------------------
|    second form    |
|                   |
---------------------
----------   --------
| delete |   | edit |
----------   --------
---------------------
|    third form     |
|                   |
---------------------
----------   --------
| delete |   | edit |
----------   --------
.........

当扩展时就是这样

---------------------
|    first form     |
|                   |
---------------------
----------   ----------
| submit |   | cancel |
----------   ----------
---------------------
|    second form    |
|                   |
---------------------
----------   ----------
| submit |   | cancel |
----------   ----------
---------------------
|    third form     |
|                   |
---------------------
----------   ----------
| submit |   | cancel |
----------   ----------
.........

从昨天开始,我一直在努力,但没有成功,最终还是失败了。

这里可能有什么问题?

正如我在评论中提到的,form的结束标记似乎丢失了。