【问题标题】:Insert text from a Text Area in a MySQL DB (Python/Flask)从 MySQL DB 中的文本区域插入文本(Python/Flask)
【发布时间】: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


    【解决方案1】:

    欢迎。

    无法辨认“我尝试了任何方法,但我没有得到正确的代码”。

    无论如何,列外

    (Vorname,Nachname,Nachricht)

    似乎只有 Nachricht 获得了 (feedtxt) 的值。

    尝试在 VALUES

    内给出 3 个项目

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      相关资源
      最近更新 更多