【发布时间】:2012-09-15 10:09:32
【问题描述】:
我在使用 GridFS 图片进行循环时遇到问题:
class VentesHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
user = self.get_secure_cookie("mechtari")
info = tornado.escape.json_decode(user)
email = info["personnel"]["email"]
produits = self.db.users.find({"personnel.email":email},{"produit_up":1, "_id":0}).distinct("produit_up")
produit_pic_id = self.db.users.find({"personnel.email":email}).distinct("produit_up.avatar.photo")
orientation = self.db.users.find({"personnel.email":email}).distinct("produit_up.avatar.orientation")
renderer = self.fs
self.render("ventes.html", produits=produits, produit_pic_id=produit_pic_id, orientation=orientation, renderer=renderer)
和模板:
{% for produit in produits %}
{% for id in produit_pic_id %}
<div class="produit">
{% import pymongo %}
{% if orientation=="portrait" %} <!-- dumb technic to avoid image stretching ^_^ -->
<span><img src="/{{renderer.get(pymongo.son_manipulator.ObjectId([id for id in produit_pic_id])).filename}}" height="200px" class="imag">
{% else %}
<span><img src="/{{renderer.get(pymongo.son_manipulator.ObjectId(id)).filename}}" width="200px"class="imag">
{% end %}
</div>
</div>
{% end %}
{% end %}
{% end %}
我得到的图片重复上传产品的时间!所以如果我 上传 2 个产品 (product_up),然后我会得到 4 个产品 产品图片可以切换! 顺便说一句,注意要避免的黑客(自我未定义......) 那么进口呢?我做另一个变量吗
x = pymongo.son_manipulator
避免模板加载整个模块 并且占用大量内存?
【问题讨论】: