简体   繁体   中英

Passing json object as argument to render() in jinja2 python

I trying to create a json object and pass that object to template.render(JSONObj) , but there is some error saying

ValueError: dictionary update sequence element #0 has length 1; 2 is required

What am I doing wrong?

You have to give that "JSONObj" object a key value. The template recieves a dictionary with objects and values to render inside it. So, try using this:

template.render(jsonobj=JSONObj)

Then, in your template, you can use this object this way:

{{jsonobj.some_key_inside_json_object}}

This jsonobj is a name that identifies your "JSONObj" object inside the template's arguments.

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM