Chameleon tal:repeat issue with JSON having "keys" section

ยอดดู 36 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Sami Pietilä

ยังไม่อ่าน,
7 ต.ค. 2558 13:14:587/10/58
ถึง pylons-discuss
Hi,

I have a database containing JSON objects. The database JSON contain a block named "keys". (For example: "keys": [{...}, {...}])

I am trying to render the keys block with chameleon template with tal:repeat="key record.keys". It seems that this syntax somehow fails to handle JSON if it has a block called "keys".

Can I use some other syntax for tal:repeat which do not fail to "keys" value? I have tried to write this differently like: tal:repeat="key record['keys'], but it did not seem to work either.

Thanks






Tres Seaver

ยังไม่อ่าน,
7 ต.ค. 2558 13:44:077/10/58
ถึง pylons-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I just created a project using the Pyramid 'starter' template, and edited
the 'mytemplate.pt' Chameleon template to include the following:

<ul>
<li tal:repeat="key document['keys']">Key: ${key}</li>
</ul>

I then updated the 'views.myview' function to return a document with 'keys':


@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
return {'project': 'chammy',
'document': {'keys': ['AAA', 'BBB', 'CCC']},
}

The view/template renders the keys as expected.


Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJWFVnMAAoJEPKpaDSJE9HY3xUP+gIAOvssSsgBqU/IWutxdEtG
L8310KWQnauLXVopxp/KPnvSTFzwciBc+U0OMrD980OAk1Kh8ATlEevihErN27sZ
zEwOqlq+2t1saV8rYWKNjkcj4QPAuIdJyI+vFvf0juBnrLUkJpXCnp+lawSX2dLJ
uOAVyxjMQzs1/9+LwJsjezpXQ45UkIbn6GDQ8OcmFjBhx+JQVjmWMjXIcku4Ar01
bs1TsvvaDT8KpyujVKymfc+kssYzTGG7/lQ5CuUV8jQK/9PYRDcWTMeLrVOYHR98
8hKRTdLZwAiKdBNrAM6Aftg1Ii/MzVCC+unolrsh2choFOhmDPDfLeQxqoLEGqfB
gJG1NaDGSCsmyWsMl5RzJg5DyEe5DCiOBVOp8XBU9drNn4hYKVNtGaOVGZBtJTDM
C/WOVoK5Y/J+vQPTDIR+3s1fwwmlXMhqnBAyEF9ZbUFfaekphR7EvFnwEDNnpE2N
pmXlo9KttqktGuAg6QL8DEbNrYCN0UpDedIPtzrtM/jTfMtrcSOlxSqByCH2vkYL
9TnDMXbnNJeFCf5Gl5mUC4rspUP4+V5EimDBSUTc2OTA7LIo21keOe0drSB9/jXO
4rCcnhy5QIlfPS3pDuUMv/KxtZ8XimIWrNsMXCuWpW9Se9sp4GL+QXo+zO3fSSui
KrjGFh6pOxDxSZRyPmKZ
=IOuX
-----END PGP SIGNATURE-----

Sami Pietilä

ยังไม่อ่าน,
7 ต.ค. 2558 16:25:417/10/58
ถึง pylons-discuss, tse...@palladion.com
Hi Tres,

With your example I got the tal:repeat to work with my JSON. 

Thank you!
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ