さて、私は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>
これは私のdatabsemodelで、これも同じです
# 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')
さて、この最後の例は完全には機能しません。すべてのコメントと日付を取得して正しく表示しますが、画像は表示しません。
私はこれに固執しているので、どんな入力でも大歓迎です。