从MySQL DB(Python / Flask)的文本区域插入文本

问题描述 投票:0回答:1

我想为我的主页编写一个小消息提要。我想从文本区域向我的数据库发送文本这是我的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
1个回答
0
投票

Welcome

© www.soinside.com 2019 - 2024. All rights reserved.