且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用谷歌应用程序引擎在django的模板上显示图像

更新时间:2023-11-20 22:18:07

假设


  • 您将图片上传到blobstore

  • image.key是blobstore密钥

  • / pictures / models\。(。*)/



命名为BlobstoreImageHandler的处理程序

然后你可以做类似于

  class BlobstoreImageHandler(blobstore.handler.BlobstoreDownloadHandler):
def get (资源):
resourse = str(urllib.unquote(资源))
blob_info = blobstore.BlobInfo.get(资源)
self.send_blob(blob_info)

这是直接从 http://code.google.com/appengine/docs/python/blobstore/overview.html#Serving_a_Blob


i am using google app engine with django to make a small application that it has these features

  1. upload images ,
  2. show images ,
  3. minipulate images (rotate)

well after finishing part 1 , now i am somewhere stuck in part 2 where i need to show images.
i did everything i retrieved the image keys, but the images are not showing.
only the titles of the images i saved in the datastore.

here is my code:

    <ul>
        {% for image in image.all %}
            <li>{{ image.title }}   </li>
            <li> <img  src="/pictures/models.{{image.key}}"/>   </li>
        {% endfor %}
    </ul>

Assuming

  • You uploaded the images to the blobstore
  • image.key is the blobstore key
  • You have a handler named BlobstoreImageHandler for /pictures/models\.(.*)/

Then you'd do something like

class BlobstoreImageHandler(blobstore.handler.BlobstoreDownloadHandler):
  def get(self, resource):
    resourse = str(urllib.unquote(resource))
    blob_info = blobstore.BlobInfo.get(resource)
    self.send_blob(blob_info)

which is straight out of http://code.google.com/appengine/docs/python/blobstore/overview.html#Serving_a_Blob