使用谷歌应用程序引擎在django的模板上显示图像 [英] show images on the templates of django using google app engine
问题描述
我正在使用谷歌应用程序引擎与Django一起制作一个小应用程序,它具有这些功能
- 上传图片,
- 显示图片,
- 微缩图片(旋转)
完成第1部分后,现在我在某处停留在第2部分,我需要显示图像。
i尽我所能检索图像键,但图像不显示。
only我保存在数据存储中的图像的标题。
这里是我的代码:
< ul>
{image for image.all%中的图片%}
< li> {{image.title}}< / li>
< li> < img src =/ pictures / models。{{image.key}}/> < /锂>
{%endfor%}
< / ul>
假设
- 您将图片上传到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
- upload images ,
- show images ,
- 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
这篇关于使用谷歌应用程序引擎在django的模板上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!