Hi my usage of get_serving_url is serverside now I wonder if this can be done in template instead of iterating serverside?
class Ad(GeoModel,search.SearchableModel):
.......
class Image(db.Model): #migrate to blobstore
reference = db.ReferenceProperty(Ad, collection_name='matched_images', verbose_name="Title")
primary_image = blobstore.BlobReferenceProperty()
.........
class AdHandler(I18NHandler):
def get(self, id):
ad = Ad.get_by_id(long(id))
image = ad.matched_images.get()
url = ''
if image:
url = images.get_serving_url(str(image.primary_image.key()))
if not ad:
self.error(404)
return
imv = []
L = {}
table = ''
for i in ad.matched_images:
if i.primary_image:
i1 = images.get_serving_url(开发者_如何学运维str(i.primary_image.key()))
imv.append(i1)
self.render_template("imageinfo.html",
{'url':url, 'imv':imv, 'ad':ad, 'image': image,
'logout_url': users.create_logout_url('/'),}
)
I´d suggest you store the image url in the database. This url´s are static, and whenever you do a get_serving_url theres a lot of CPU time involved. I saw a drastic improvement in my own app when I did this. Also, by doing so, your initial problem will be solved immediately.
精彩评论