【问题标题】:With Python, GAE and Tipfy, unable to pass a db.key as parameter for image retrieval使用 Python、GAE 和 Tipfy,无法将 db.key 作为参数传递给图像检索
【发布时间】: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


    【解决方案1】:

    所以,我设法让它工作,解决方案是从

    {% for pic in photo_list %}
      <tr>
      <td><img src='getPic?img_id={{ pic.key }} '></img></td>
    

    {% for pic in photo_list %}
      <tr>
      <td><img src='getPic?img_id={{ pic.key() }} '></img></td>
    

    欢迎任何人评论为什么这是解决方案

    【讨论】:

    • 可能tipfy没有使用与webapp相同的模板语言。
    • 当然,tipfy 使用 jinja,webapp 使用 django - 但我仍然不明白为什么它代表所有其他领域,例如{{ pic.date }} 正确,但不是 {{ pic.key }}
    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多