我有一个小的.py程序,呈现两个HTML页面。其中一个HTML页面中有一个表单。一种请求名字和注释的基本形式。我不知道如何从表单中获取名称和注释并将其存储到csv文件中。我已经得到了编码,所以我已经手动输入到csv文件中的一小部分被打印/返回到HTML页面上,这是目标之一。但我无法将输入表单的数据放入csv文件,然后返回HTML页面。我觉得这是一个简单的解决办法,但这本书对我来说完全没有意义,我有阅读障碍,我发现不可能理解这些例子和书面解释。
This is the code I have for reading the csv back onto the page;
@app.route('/guestbook')
def guestbook():
with open('nameList.csv','r') as inFile:
reader=csv.reader(inFile)
names=[row for row in reader]
return render_template('guestbook.html',names=names[1:])
And this is my form coding;
<h3 class="tab">Feel free to enter your comments below</h3>
<br />
<br />
<form action="" method="get" enctype="text/plain" name="Comments Form">
<input id="namebox" type="text" maxlength="45" size="32" placeholder="Name"
class="tab"/>
<br />
<textarea id="txt1" class="textbox tab" rows="6" placeholder="Your comment"
class="tab" cols="28"></textarea>
<br />
<button class="menuitem tab" onclick="clearComment()" class="tab">Clear
comment</button>
<button class="menuitem" onclick="saveComment()" class="tab">Save comment</button>
<br>
</div>
目前没有回答
相关问题 更多 >
编程相关推荐