<分区>
由于 GET
,我得到了一个响应对象请求,我已将其转换为 JSON
与 jsonify()
.当我将其传递给模板时,我得到的只是一个 JSON 对象,例如:<Response 1366 bytes [200 OK]>
这。
#request.py
...
response = requests.get('http://www.example.com')
response_json = jsonify(all=response.text)
return render_template(
'results.html',
form=ReqForm(request.form),
response=response_json,
date=datetime.datetime.now()
)
和模板..
#results.html
...
<div class="results">
{{ response }} # --> gives <Response 1366 bytes [200 OK]>
</div>
...
如何在模板中漂亮地显示此 JSON?