【问题标题】:set data in html django在 html django 中设置数据
【发布时间】:2018-08-07 01:43:43
【问题描述】:

我正在学习 django rest。现在我不会在 html 中输出一些 json 数据。我的json:

{'Resul': {'Period Start': '2017-01-01', 'Period End': '2017-12-12'}}

然后我将它的 json 发送到 html:

 context = {'Resul': json_data['date']}
 content = render_to_string('balance.html', context)

json_data['date'] - {'Period Start': '2017-01-01', 'Period End': '2017-12-12'}

在html中我写了这段代码

 Period: {{ Resul['Period Start'] }} - {{ Resul['Period End'] }}

但有错误:

Could not parse the remainder: '['Period Start']' from 'Resul['Period Start']'

【问题讨论】:

标签: html json django


【解决方案1】:

我强烈建议您不要在字典键名中使用空格,将它们更改为下划线并这样做:

 Period: {{ Resul.Period_Start }} - {{ Resul.Period_End }}

【讨论】:

    猜你喜欢
    • 2018-05-30
    • 2012-12-14
    • 2014-10-07
    • 2018-05-06
    • 2011-07-20
    • 2019-10-13
    • 2021-06-23
    • 2018-06-07
    相关资源
    最近更新 更多