Python 3.x JINJA2中的GCP数据存储渲染也显示了完整的密钥
因此,我将来自Python 3.x JINJA2中的GCP数据存储渲染也显示了完整的密钥,python-3.x,google-cloud-datastore,jinja2,Python 3.x,Google Cloud Datastore,Jinja2,因此,我将来自ds\u data=list(query.fetch())的结果传递给JINJA2: return render\u模板('index.html',images=ds\u数据) 对于python,这可以作为列表进行迭代,没有问题,但对于JINJA2: data json=“{{image | safe}}” 与HTML中的dict:'{}'不同,我还有一个完整的键: data-json="<Entity('kind', 'id') {'someDictKey': 'value
ds\u data=list(query.fetch())
的结果传递给JINJA2:
return render\u模板('index.html',images=ds\u数据)
对于python,这可以作为列表进行迭代,没有问题,但对于JINJA2:
data json=“{{image | safe}}”
与HTML中的dict:'{}'
不同,我还有一个完整的键:
data-json="<Entity('kind', 'id') {'someDictKey': 'value', 'someDictKey': 'value'}>"
data json=“”
嗯,你知道我如何在python中删除实体的键,或者在JINJA2中正确地呈现它吗
模板片段:
{% block content %}
{% if images is defined %}
<div class="main-content" id="main-content">
...
{% for image in images %}
<tbody id="tbody{{ image['key'] }}" data-json="{{ image }}">
</tbody>
{% endfor %}
...
{% endif %}
{% endblock %}
{%block content%}
{%如果定义了图像%}
...
{%用于图像中的图像%}
{%endfor%}
...
{%endif%}
{%endblock%}
谢谢大家! 实际上,您必须将数据转换为json字符串。例如,
json.dumps(图像)
。具体地说,您可以看到您需要将image
转换为dict以获得所需的映射()。您实际上需要将数据转换为json字符串。例如,json.dumps(图像)
。具体地说,您可以看到,您需要将图像
投射到dict以获得所需的地图()。这毕竟是我昨晚所做的:
@app.template_filter('parse_entity_list')
def parse_filter(item):
# Recompose DS object to list of dicts
a = json.dumps(item)
return a
app.jinja_env.filters['parse_entity_list'] = parse_filter
金甲2号方:
毕竟,我昨晚就是这么做的:
@app.template_filter('parse_entity_list')
def parse_filter(item):
# Recompose DS object to list of dicts
a = json.dumps(item)
return a
app.jinja_env.filters['parse_entity_list'] = parse_filter
金甲2号方:
能否提供访问变量的模板片段?能否提供访问变量的模板片段?谢谢!我在跳,我错过了什么。我已经发布了昨晚完成的完整解决方案,谢谢!我在跳,我错过了什么。我已经发布了昨晚完成的完整解决方案