HTMLページを解析し、すべての画像タグを見つけてdjangoテンプレートに表示しようとしています
見る
import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen("http://www.flipkart.com/")
soup = BeautifulSoup(page)
tags=soup.findAll('img')
template = get_template('welcome.html')
variables = RequestContext(request,{'tags':tags})
output = template.render(variables)
return HttpResponse(output)
テンプレート
{% block content %}
<div class="row">
<ul class="thumbnails">
{% for row in tags %}
<li >
<span>Flash</span>
<a href="#" class="thumbnail">
{{ row }}
</a>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
タグを印刷しました
[<img src="http://passets-cdn.pinterest.com/images/search.gif" alt="" />, <img src="http://media-cache2.pinterest.com/upload/422281184577033_NvxwzARh_b.jpg" alt="#wedding #bouquet #flowers" class="PinImageImg" style="height: 288px;" />, <img src="http://media-cache0.pinterest.com/avatars/heygirlfriend-33.jpg" alt="Profile picture of Heather Carpenter" />, <img src="http://media-cache2.pinterest.com/avatars/lilizzy08_1330284092.jpg" class="profile user_image" alt="Profile picture of JoAnn Boyle Barker" />, <img src="http://media-cache2.pinterest.com/avatars/camelotparty_1330114747.jpg" class="profile user_image" alt="Profile picture of Camelot Party" />, <img src="http://media-cache5.pinterest.com/avatars/mamababe13_1327965590.jpg" class="profile user_image" alt="Profile picture of Irene Hardin Sanchez" />, <img src="http://media-cache5.pinterest.com/avatars/mpowers213_1333304368.jpg" class="profile user_image" alt="Profile picture of Maggie Powers" />, <img src="http://media-cache7.pinterest.com/avatars/apricot1026_1334529181.jpg" class="profile user_image" alt="Profile picture of Michelle Nadel" />, <img src="http://media-cache4.pinterest.com/upload/169025792234929326_WtMMM67J_b.jpg" alt="Dr. Oz Metabolism Booster" class="PinImageImg" style="height: 256px;" />, <img src="http://media-cache6.pinterest.com/avatars/karenmigala_1332630951.jpg" alt="Profile picture of Karen Migala" />, <img src="http://media-cache9.pinterest.com/avatars/dutchjohnson-26.jpg" class="profile user_image" alt="Profile picture of Dutch Johnson" />]
タグを印刷しようとすると、たくさんの img タグがありますが、ブラウザーに空のリストが表示されます (表示されている場合)。
HTML page Displays
[] [] [] [] [] [] のような複数の空のリスト
Rendered Content
<li >
<span>Flash</span>
<a href="#" class="thumbnail">
[]
</a>
</li>
<li >
<span>Flash</span>
<a href="#" class="thumbnail">
[]
</a>
</li>
<li >
<span>Flash</span>
<a href="#" class="thumbnail">
[]
</a>
</li>
<li >
<span>Flash</span>
<a href="#" class="thumbnail">
[]
</a>
</li>
<li >
<span>Flash</span>
<a href="#" class="thumbnail">
[]
</a>
</li>
助けてください