【发布时间】:2011-03-06 10:35:35
【问题描述】:
好的,所以我正在和tipfy 一起玩,制作一个简单的照片库。我有一个使用 webbapp 的有效解决方案,这是我的模板,browse.htm,在两个示例中都保持不变:
{% for pic in photo_list %}
<tr>
<td><img src='getPic?img_id={{ pic.key }} '></img></td>
<td>{{ pic.description }}</td>
<td>{{ pic.date }}</td>
</tr>
这是我的数据库模型,也是一样的
# This is the datamodell for the photos
class dbPhotos(db.Model):
pic = db.BlobProperty() # The photo itself
description = db.StringProperty(multiline=True) # an optional description to each photo from the uploader
date = db.DateTimeProperty(auto_now_add=True) # date and time of upload
所以,使用 webapp,我的脚本是:
# the handler for the gallery page
class BrowseHandler(webapp.RequestHandler):
def get(self):
que = db.Query(dbPhotos)
photos = que.fetch(limit=100)
outstr = template.render('browse.htm', {'photo_list': photos})
handler.response.out.write(outstr)
# serve pics to template
class getPicHandler(webapp.RequestHandler):
def get(self):
userphoto = db.get(self.request.get("img_id"))
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(userphoto.pic)
所以,这很完美。现在,我尝试使用tipfy:
# the handler for the browse-page
class browseHandler(RequestHandler):
def get(self):
que = db.Query(dbPhotos)
photos = que.fetch(limit=100)
return render_response('browse.ji', photo_list=photos)
# serve pic to view
class getPicHandler(RequestHandler):
def get(self):
id = self.request.args.get("img_id")
userphoto = db.get(id)
return Response(userphoto.pic, mimetype='image/png')
现在,最后一个示例无法完美运行。 它会获取所有 cmets 和日期并正确显示它们,但 没有图片。
我很坚持,欢迎任何意见。
【问题讨论】:
标签: python google-app-engine tipfy