我用这个方法来调整png图像的大小:
但这张图片仍然失去透明度:
import Image, numpy
def resize(filename, img,height, width):
if filename.endswith(".png"):
img = img.convert('RGBA')
premult = numpy.fromstring(img.tostring(), dtype=numpy.uint8)
alphaLayer = premult[3::4] / 255.0
premult[::4] *= alphaLayer
premult[1::4] *= alphaLayer
premult[2::4] *= alphaLayer
img = Image.fromstring("RGBA", img.size, premult.tostring())
img = img.resize((height,width), Image.ANTIALIAS)
return img
Run Code Online (Sandbox Code Playgroud)
从
至

我看到了文档 https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_integer_id
返回最后一个(kind,id)对中的整数id,如果密钥具有字符串id或不完整,则返回None.
看,我认为一个键的id可以是一个int; 所以我写
r = ndb.Key(UserSession, int(id)).get()
if r:
return r.session
Run Code Online (Sandbox Code Playgroud)
但是dev_server.py会一直提升
File "/home/bitcoin/down/google_appengine/google/appengine/datastore/datastore_stub_util.py", line 346, in CheckReference
raise datastore_errors.BadRequestError('missing key id/name')
BadRequestError: missing key id/name
Run Code Online (Sandbox Code Playgroud)
我支持int(id) - > str(id)
似乎是正确的
所以我的问题是,如何使用整数_id的ndb键?
这个模型是
class UserSession(ndb.Model):
session = ndb.BlobProperty()
Run Code Online (Sandbox Code Playgroud) 我写代码如下
from google.appengine.ext import ndb
__metaclass__ = type
class UserSession(ndb.Model):
session = ndb.BlobProperty()
class KV:
@staticmethod
def get(id):
r = ndb.Key(UserSession, int(id)).get()
if r:
return r.session
@staticmethod
def set(id, value):
return UserSession.get_or_insert(int(id), session=value)
@staticmethod
def delete(id):
ndb.Key(UserSession, int(id)).delete()
Run Code Online (Sandbox Code Playgroud)
我写的地方
id = 1
key = ndb.Key(UserSession, int(id))
UserSession.get_or_insert(key, session=1)
Run Code Online (Sandbox Code Playgroud)
sdk加注
TypeError: name must be a string; received Key('UserSession', 1)
Run Code Online (Sandbox Code Playgroud)
当我打电话给KV.get()
sdk加注
文件"/home/bitcoin/42btc/zapp/_plugin/auth/model/gae/user.py",第14行,获取
r = ndb.Key(UserSession,int(id)).get()
Run Code Online (Sandbox Code Playgroud)
...
BadRequestError:缺少密钥ID /名称
那么,如何使用NDB?
python ×1