Ceci est un extrait de mon code.Pourquoi le render_to_response ne fonctionne pas correctement
soup=BeautifulSoup(html_document)
tabulka=soup.find("table",width="100%")
dls=tabulka.findAll("dl",{"class":"resultClassify"})
tps=tabulka.findAll("div",{"class":"pageT clearfix"})
return render_to_response('result.html',{'search_key':search_key,'turnpages
':tps,'bookmarks':dls})
J'ai vérifié le DLS, il est un dict ne contient qu'une seule étiquette html
<dl>label contents contains some <dd> labels</dl>
Mais après DLS passe à render_to_response le résultat est incorrect. Le code de modèle correspondant dans result.html est:
{% if bookmarks %}
{% for bookmark in bookmarks %}
{{bookmark|safe}}
{% endfor %}
{% else %}
<p>No bookmarks found.</p>
{% endif %}
Le résultat sortie html contient un format de dictionnaire python comme ceci:
[<dd>some html</dd>,<dd>some html</dd>,<dd>some html</dd>,...]
Cela apparaît dans le code HTML de sortie. C'est très étrange. Est-ce un bug de renfer_to_response?
+1 pour mentionner l'aspect de sécurité – heinrich5991