LoginSignup
0
1

More than 5 years have passed since last update.

SQLite3で躓いたところ

Posted at

躓いたところ

以下のようなフォームでチェックボックスにチェックを入れられたデータを消したかったわけです。

index.html
<form action="{{ url_for('delete_data') }}" method="post" enctype="multipart/form-data">
  <ul>
    {% for entry in result %}
      <li>
        <input type="checkbox" name="action" value="{{ entry[0] }}">{{ entry[1] }}:{{ entry[2] }}
      </li>
    {% endfor %}
  </ul>
  <input type="submit" value="削除">
</form>
index.py
if request.method == 'POST':
  data_ids= request.form['action']

こういう感じで受け取った、変数を渡したかったんですね。

index.py
c.execute('''DELETE FROM message WHERE data_id=data_ids''')

これで何度も怒られる。

結論

こう書けば良かった模様。変数で渡す場合はこうなるんですねぇ・・・。

index.py
query = "DELETE FROM message WHERE data_id=?"
c.execute(query,(data_ids,))
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1