質問編集履歴
2
コードの変数を下記コメントの通りに修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
上記から、create構文でtableが作られてないことが原因と考えられます。
|
22
22
|
ayad/initのcreate構文はどこがエラーなのでしょうか…?
|
23
23
|
|
24
|
-
```
|
24
|
+
```python
|
25
25
|
import sqlite3
|
26
26
|
from bottle import Bottle, post, get, request, route, run, template
|
27
27
|
|
@@ -33,7 +33,9 @@
|
|
33
33
|
|
34
34
|
drop_tb = 'DROP TABLE IF EXISTS diet_table'
|
35
35
|
#table削除
|
36
|
+
create_tb = 'CREATE TABLE diet_table('+\
|
37
|
+
'id INTEGER PRIMARY KEY AUTOINCREMENT, '+\
|
36
|
-
|
38
|
+
'time DATE, weight DOUBLE NOT NULL, step BIGINT NOT NULL, contents TEXT NOT NULL)'
|
37
39
|
#tableを作成
|
38
40
|
|
39
41
|
cur = con.cursor()
|
@@ -44,7 +46,7 @@
|
|
44
46
|
|
45
47
|
cur.execute(create_tb)
|
46
48
|
#create_tb関数を呼び出し、executeで実行
|
47
|
-
insert(cur, '', '1', '1', 'テスト')
|
49
|
+
#insert(cur, '', '1', '1', 'テスト')
|
48
50
|
|
49
51
|
con.commit()
|
50
52
|
#blist変数の中にtableの中の情報をすべて取得
|
@@ -54,22 +56,22 @@
|
|
54
56
|
con.close()
|
55
57
|
|
56
58
|
#%for~%endまでは登録した情報を表示する
|
57
|
-
if len(
|
59
|
+
if len(diet_table) > 0 :
|
58
60
|
tplt = """
|
59
61
|
<p>テーブルbottlesを作成しました</p>
|
60
62
|
<p>
|
61
|
-
%for cell in
|
63
|
+
%for cell in diet_table[-1]:
|
62
64
|
{{cell}},
|
63
65
|
%end
|
64
66
|
</p>
|
65
67
|
"""
|
66
|
-
return template(tplt,
|
68
|
+
return template(tplt, diet_table=diet_table)
|
67
69
|
|
68
70
|
return ('初期化操作失敗')
|
69
71
|
|
70
72
|
@route('/ayad')
|
71
73
|
def get_list():
|
72
|
-
con = sqlite3.connect('
|
74
|
+
con = sqlite3.connect('diet.db')
|
73
75
|
cur = con.cursor()
|
74
76
|
blist = select_all(cur)
|
75
77
|
con.close()
|
@@ -80,7 +82,7 @@
|
|
80
82
|
<p><a href='/login'>管理者用</a></p>
|
81
83
|
<hr>
|
82
84
|
<table>
|
83
|
-
%for b in
|
85
|
+
%for b in diet_table:
|
84
86
|
<tr>
|
85
87
|
<td>{{b[0]}}</td>
|
86
88
|
<td><a href='/ayad/{{b[0]}}'>{{b[1]}}</a></td>
|
@@ -88,7 +90,7 @@
|
|
88
90
|
%end
|
89
91
|
</table>
|
90
92
|
"""
|
91
|
-
return template(tplt,
|
93
|
+
return template(tplt, diet_table=diet_table)
|
92
94
|
|
93
95
|
#入力した情報の詳細を表示
|
94
96
|
#↓
|
@@ -143,7 +145,7 @@
|
|
143
145
|
tplt = """
|
144
146
|
<h1>データを保存しました</h1>
|
145
147
|
""" + detail_template()
|
146
|
-
return template(tplt, clms=CLMS, btl =
|
148
|
+
return template(tplt, clms=CLMS, btl = diet_table[-1])
|
147
149
|
|
148
150
|
|
149
151
|
def detail_template():
|
@@ -163,26 +165,26 @@
|
|
163
165
|
|
164
166
|
|
165
167
|
def insert(cur, time, weight, step, contents):
|
166
|
-
insert_str = 'INSERT INTO
|
168
|
+
insert_str = 'INSERT INTO deit_table(time, weight, step, contents)' +\
|
167
169
|
'VALUES (?,?,?,?)'
|
168
170
|
cur.execute(insert_str, (time, weight, step, contents))
|
169
171
|
|
170
172
|
def select_all (cur):
|
171
|
-
select_str = 'SELECT * FROM
|
173
|
+
select_str = 'SELECT * FROM diet_table'
|
172
174
|
cur.execute(select_str)
|
173
175
|
return cur.fetchall()
|
174
176
|
|
175
177
|
def select_by_id(cur, id):
|
176
|
-
select_str = 'SELECT * FROM
|
178
|
+
select_str = 'SELECT * FROM diet_table WHERE id= ?'
|
177
179
|
cur.execute(select_str, id)
|
178
180
|
return cur.fetchone()
|
179
181
|
|
180
182
|
def update(cur, id, time, weight, step, contents):
|
181
|
-
upd_str = 'UPDATE
|
183
|
+
upd_str = 'UPDATE diet_table SET time=?, weight=?, step=?, contents=? WHERE id =?'
|
182
184
|
cur.execute(upd_str, (time, weight, step, contents, id) )
|
183
185
|
|
184
186
|
def delete(cur, id):
|
185
|
-
delete_str = 'DELETE FROM
|
187
|
+
delete_str = 'DELETE FROM diet_table where id=?'
|
186
188
|
cur.execute(delete_str, id)
|
187
189
|
|
188
190
|
CLMS=[('time', '日付'), ('weight', '体重'), ('step', '歩数'), ('contents', '内容')]
|
1
エラーの原因の行がayad/initのcreate構文を突き止めましたが、なぜその行がエラーなのかがわかりません...
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,6 +16,10 @@
|
|
16
16
|
**調べたこと**
|
17
17
|
sqliteで取り扱っていないデータ型を選択していないか調べたのですが、このwebアプリで使用しているデータ型は問題ありませんでした。
|
18
18
|
|
19
|
+
**追記**
|
20
|
+
ayad/initのinsert文をコメントアウトし、デバックを確認すると、ayad/initのところにのif文のところで「tableがない」となりました。
|
21
|
+
上記から、create構文でtableが作られてないことが原因と考えられます。
|
22
|
+
ayad/initのcreate構文はどこがエラーなのでしょうか…?
|
19
23
|
|
20
24
|
```ここに言語を入力
|
21
25
|
import sqlite3
|