前提
DBliteとPythonを使ったWebアプリケーションを作成しています。
DBでメッセージが10の時に「接続無し」5の時に「異常あり」0の時に「異常なし」と表示したいのですが、エラーを吐いてしまいます。
データベースのテーブルは「ラズパイID(主キー),クラス番号,名前,メッセージ」となっており、メッセージ以外はそのまま表示して、メッセージ文だけを変えて列のまま表示させたいと考えています。
発生している問題・エラーメッセージ
TypeError: 'sqlite3.Cursor' object is not subscriptable Traceback (most recent call last) TypeError: 'sqlite3.Cursor' object is not subscriptable
該当のソースコード
python
1@egamipro.route('/setuzoku', methods=["POST"])#ラズパイを照合する 2def setuzoku(): 3 4 # データベースを開く 5 con = get_db() 6 7 # 商品一覧を読み込み 8 a = con.execute("select * from kfc") 9 b = a.fetchall() 10 mail = con.execute("select メッセージ from kfc") 11 kcs=mail.fetchall() 12 c=b[0][0] 13 ima=kcs[0][0] 14 if mail == 10: 15 ima[0][0] = ("接続無し") 16 else: 17 if mail == 5: 18 ima[0][0] = ("異常あり") 19 else: 20 ima[0][0] = ("異常なし") 21 22 23 con.close() 24 25 return render_template('setuzoku.html', data = c,ima = ima)
HTML
1<!DOCTYPE html> 2<html lang="jp"> 3<head> 4 <meta charset="UTF-8"> 5 <title>朝の4時から夜の12時までの労働を強要されます</title> 6</head> 7<body> 8 <div> 9 <table> 10 <thead> 11 <tr> 12 <th>ラズパイコード</th> 13 <th>接続先:クラス番号</th> 14 <th>名前</th> 15 <th>状態</th> 16 </tr> 17 </thead> 18 <tbody> 19 {% for item in data %} 20 <tr> 21 <th>{{item[0]}}</th> 22 <th>{{item[1]}}</th> 23 <th>{{item[2]}}</th> 24 25 {% endfor %} 26 {% for item in ima %} 27 <th>{{item[0]}}</th> 28 </tr> 29 30 </tbody> 31 </table> 32 33 <button type="button" onclick="history.back()">戻る</button> 34 </div>
試したこと
if文の作成、while文の作成、配列の作成など
補足情報(FW/ツールのバージョンなど)
vscode使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/11/21 02:53
2022/11/21 04:04
2022/11/22 00:31 編集
2022/11/22 01:05