回答編集履歴
1
修正
test
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
+
- 提示されたjsonデータの辞書部分、カンマが含まれていないようですので、カンマで区切る必要があります。
|
2
|
+
|
3
|
+
- `test_find()`の戻り値がJSON文字列であれば、`json.loads`でデータ化する必要があります。
|
4
|
+
|
1
|
-
`return render_template('test.html',test=test_data[0])`ではないでしょうか?
|
5
|
+
- `return render_template('test.html',test=test_data[0])`ではないでしょうか?
|
6
|
+
|
7
|
+
|
2
8
|
|
3
9
|
以下当方での検証コードと結果です。テンプレートは提示HTMLをそのまま利用しています。
|
4
10
|
|
5
11
|
```Python
|
6
12
|
|
7
13
|
from flask import Flask, render_template
|
14
|
+
|
15
|
+
import json # 追加
|
8
16
|
|
9
17
|
app = Flask(__name__)
|
10
18
|
|
@@ -22,9 +30,15 @@
|
|
22
30
|
|
23
31
|
def test():
|
24
32
|
|
25
|
-
test_data = [{"username":"test", "password":"test", "memo":"hogehoge"}] # = test_find()
|
33
|
+
test_data = '[{"username":"test", "password":"test", "memo":"hogehoge"}]' # = test_find()
|
34
|
+
|
35
|
+
print(test_data) # [{"username":"test", "password":"test", "memo":"hogehoge"}]
|
36
|
+
|
37
|
+
test_data = json.loads(test_data) # json文字列をデータに変換
|
26
38
|
|
27
39
|
print(test_data) # [{'password': 'test', 'username': 'test', 'memo': 'hogehoge'}]
|
40
|
+
|
41
|
+
|
28
42
|
|
29
43
|
return render_template('test.html',test=test_data[0])
|
30
44
|
|