這是我的代碼片段。爲什麼render_to_response無法正常工作
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})
我檢查了DLS,它是一個字典只包含一個HTML標籤
<dl>label contents contains some <dd> labels</dl>
但經過通DLS選擇render_to_response到的結果是不正確的。 在result.html相應的模板的代碼是:
{% if bookmarks %}
{% for bookmark in bookmarks %}
{{bookmark|safe}}
{% endfor %}
{% else %}
<p>No bookmarks found.</p>
{% endif %}
輸出結果的HTML包含這樣一個Python字典格式:
[<dd>some html</dd>,<dd>some html</dd>,<dd>some html</dd>,...]
這出現在輸出HTML。這很奇怪。這是一個renfer_to_response的bug嗎?
+1提到的安全性方面 – heinrich5991