我正在尝试获取图像的 URL(GAE 的 blob 字段):
class Product(db.Model):
name = db.StringProperty()
price = db.FloatProperty()
added = db.DateTimeProperty(auto_now_add=True)
image = db.BlobProperty(default=None)
url = images.get_serving_url(movie.image)
服务图像处理程序:
def result(request):
product = Product()
product.name = "halva"
url = 'http://echealthinsurance.com/wp-content/uploads/2009/11/minnesota.jpg'
product.image = db.Blob(urlfetch.Fetch(url).content)
product.put()
template = loader.get_template("result.html")
context = RequestContext(request,
{
"result" : u"Add"})
return HttpResponse(template.render(context))
但我得到除了:
UnicodeDecodeError:
当尝试忽略此异常(这是 Python 2.7 中的错误)时,我在其他地方遇到异常。
之后我尝试将图像编码为'latin-1'('utf-8'不起作用):
enc_img = movie.image.decode("latin-1")
url = images.get_serving_url(enc_img)
结果: url 有一个类似于二进制文件的视图:
"ÝêÓ9>èýÑNëCf Äàr0xã³3Ï^µ7±\íQÀ¡>.....ÕÝ£°Ëÿ"I¢¶L`ù¥ºûMþÒ¸ÿ+ÿL¢ï£ÿÙ' alt="" />"
如何获取 url 以在模板中显示动态图像?