【发布时间】:2020-02-13 18:38:25
【问题描述】:
我想为我的主页编写一个小消息提要。我想将文本从文本区域发送到我的数据库 这是我的 html 模板:
{% extends 'layout.html'%}
{% block body%}
<form action="/feed" method="post">
<table>
<tr>
<td><textarea name="feedtext" id="feedtext" placeholder="Type message here!" rows="4" cols="53"></textarea></td>
</tr>
<tr>
<td><button style="width: 65%;" "submit"\>Send</button></td>
</tr>
</table>
</form>
{% endblock %}
现在我的问题是 python 部分。我尝试了任何方法,但没有得到正确的代码。
这是我现在的 python 代码:
@app.route('/feed', methods=['POST'])
def feed():
try:
conn = mysql.connect()
cursor = conn.cursor()
feedtxt = request.form['feedtext']
cursor.execute('INSERT INTO nachrichten (Vorname, Nachname, Nachricht) VALUES(%);', (feedtxt))
finally:
cursor.close()
conn.close()
【问题讨论】:
标签: python mysql text insert message