困っていること
Pythonで取得したJSON型の値をHTMLに送り、そのままのインデントで表示させたい
# Python def test(): test_info = [] for test in test.NameList(): test_name = test.getName(testname) test_json = test.TestJson() test = (json.dumps(test_json['Status'], indent=2, separators=(',', ': '))) print(test) test_info.append([test.getName(), test]) return render_template('test.html', test_info=test_info)
# HTML <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>test</title> </head> <body> <div> {% for test in test_info %} {% set name = test[0] %} {% set json = test[1] %} <p>名前: {{ name }}</p> <p>{{ json }}</p> {% endfor %} </div> </body> </html>
上記のようにjsonでとった値をappendし、htmlに送ると結果が全て1行につらつら書かれてしまい、インデントも適用されません。
python内で値を取得し、printした際はコンソールに正しくインデントされた状態で取得できています。
appendするとインデントがなかったことにされてしまうのでしょうか。
また、解決するにはどうしたら良いでしょうか・・・?
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/05 05:28 編集
2018/02/05 23:36 編集
2018/02/06 01:17
2018/02/06 05:11
2018/02/06 05:33