2
좋아, 그래서 tipfy로 간단한 사진 갤러리를 만들고 놀고 있습니다. 내가 webbapp를 사용하여 작업 솔루션을 가지고,이 두 예에서 모두 동일하게 유지 내 템플릿, browse.htm입니다 :Python, GAE 및 Tipfy에서 이미지 검색을위한 매개 변수로 db.key를 전달할 수 없습니다.
{% 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
을 satys 내 databsemodel입니다 따라서 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')
이제이 마지막 예는 완벽하게 작동하지 않습니다. 모든 댓글과 날짜를 가져 와서 정확하게 표시합니다 (). 사진이 없습니다.
나는 이렇게 붙어있어, 모든 입력을 환영합니다.
아마도 tipfy는 webapp과 동일한 템플릿 언어를 사용하지 않습니다. –
확실히, tipfy는 jinja를 사용하고 webapp는 django를 사용합니다. 그러나 나는 아직도 다른 모든 필드를 나타내는 이유를 얻지 못합니다. '{{pic.date}}'는 올바르게 표시하지만'{{pic.key}}'는 표시하지 않습니다. – Pedro