将循环传递给模板

时间:2014-02-13 12:15:47

标签: python django

我有这个功能:

    for kid in kids:
      image = Image.open(os.getcwd()+kid.image_url)
      wpercent = (150/float(image.size[0]))
      hsize = int((float(image.size[1])*float(wpercent)))
      img = image.resize((150,150), Image.ANTIALIAS)
      img.save(os.getcwd()+kid.image_url)
     response = self.html_response('parent/i_am_new.html', {'kids': kids})

我想将img传递给模板,以便每个孩子都可以访问img。

模板:

        {% for kid in kids %}
        {% if forloop.counter|divisibleby:5 %}<tr> {% endif %}
        <td>
            <div id="child_link_login">
            <center>
            <div  style="height:150px;margin-top:2px; margin-left:3px;">
                <a href="/kid_login_by_parent/?kid_id={{kid.user_id}}">
                <img src="{{img}}" width="150" height="150" />
                </a>
                </div>

            </center>
                <a href="/kid_login_by_parent/?kid_id={{kid.user_id}}" style="text-decoration: none; color: #999999INSTALLED_APPS">
            <center>{{kid.avatar}}</center>
            </a>
            </div>

我该如何执行此操作?

0 个答案:

没有答案