python - Accessing BeautifulSoup elemets in django template -
i'm trying display results of soap request in django template.
the results in xml i've used beautifulsoup process data , access beautifulsoup object in django template, looping through each element , calling child elements name so
{% item in bs_data %} {{ item.child1.text }} {{ item.child2.text }} {% endfor %}
i can in python, django template seems treat beautifulsoup elements if have no children, although loop through items in bs_data item.child1 empty item.0
i can't iterate through sub elements of each element.
i've looped through elements in view , created nested lists achieve same result if knows how persuade django template parse beautiful soup objects i'm dying know.
cheers
edit
ok below example xml can print different elements , step through elements printing text. below code:
b = beautifulsoup.beautifulsoup("<note>\ <to>tove</to>\ <from>jani</from>\ <heading>reminder</heading>\ <body>don't forget me weekend!</body>\ </note>") print b.to print b.body in b: print i.text
results in below output:
<to>tove</to> <body>don't forget me weekend!</body> tovejanireminderdon't forget me weekend!
however can't replicate in django template b passed template in python code above
template code:
{{ b.to }} {{ b.body }} {% in b %} {% i.text %} {% endfor %}
results in nothing, following:
{{ b }}
shows beautifulsoup object
Comments
Post a Comment