我有一个创建的非ndb实体和一个拥有此对象的webapp2用户。 是否可以将密钥保存为实例变量? 尝试执行此操作时出现异常:
'Ad' object has no attribute '_values' Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/authhandlers.py", line 21, in dispatch webapp2.RequestHandler.dispatch(self) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/main.py", line 3004, in post ad.usr = self.current_user.key File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 1039, in __set__ self._set_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 801, in _set_value self._store_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 785, in _store_value entity._values[self._name] = value AttributeError: 'Ad' object has no attribute '_values'违规代码
if self.current_user: logging.info('user:'+str(self.current_user)) ad.usr = self.current_user.key ad.put模型
class Ad(GeoModel, search.SearchableModel): primary_image = blobstore.BlobReferenceProperty() usr = ndb_model.KeyProperty() ...有没有推荐的方法来做我想做的事情?
谢谢
I have a non-ndb entity that is created and a webapp2 User who owns this object. Is it possible to keep the key as an instance variable? I get an exception trying to do this:
'Ad' object has no attribute '_values' Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/authhandlers.py", line 21, in dispatch webapp2.RequestHandler.dispatch(self) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/main.py", line 3004, in post ad.usr = self.current_user.key File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 1039, in __set__ self._set_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 801, in _set_value self._store_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 785, in _store_value entity._values[self._name] = value AttributeError: 'Ad' object has no attribute '_values'The offending code
if self.current_user: logging.info('user:'+str(self.current_user)) ad.usr = self.current_user.key ad.putModel
class Ad(GeoModel, search.SearchableModel): primary_image = blobstore.BlobReferenceProperty() usr = ndb_model.KeyProperty() ...Is there a recommended way to do what I'm trying to do?
Thanks
最满意答案
NDB和db中的密钥类型不同。 您必须将NDB密钥(self.current_user.key)转换为db.Key实例,如下所示:
ad.usr = self.current_user.key.to_old_key()请参阅https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_to_old_key
The Key types in NDB and db are different. You must convert the NDB Key (self.current_user.key) to a db.Key instance as follows:
ad.usr = self.current_user.key.to_old_key()See https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_to_old_key
如何在用户是ndb.expando时指示所有权(How to indicate ownership when user is an ndb.expando) python我有一个创建的非ndb实体和一个拥有此对象的webapp2用户。 是否可以将密钥保存为实例变量? 尝试执行此操作时出现异常:
'Ad' object has no attribute '_values' Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/authhandlers.py", line 21, in dispatch webapp2.RequestHandler.dispatch(self) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/main.py", line 3004, in post ad.usr = self.current_user.key File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 1039, in __set__ self._set_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 801, in _set_value self._store_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 785, in _store_value entity._values[self._name] = value AttributeError: 'Ad' object has no attribute '_values'违规代码
if self.current_user: logging.info('user:'+str(self.current_user)) ad.usr = self.current_user.key ad.put模型
class Ad(GeoModel, search.SearchableModel): primary_image = blobstore.BlobReferenceProperty() usr = ndb_model.KeyProperty() ...有没有推荐的方法来做我想做的事情?
谢谢
I have a non-ndb entity that is created and a webapp2 User who owns this object. Is it possible to keep the key as an instance variable? I get an exception trying to do this:
'Ad' object has no attribute '_values' Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/authhandlers.py", line 21, in dispatch webapp2.RequestHandler.dispatch(self) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/main.py", line 3004, in post ad.usr = self.current_user.key File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 1039, in __set__ self._set_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 801, in _set_value self._store_value(entity, value) File "/base/data/home/apps/s~montaoproject/sessions.358423846858516313/ndb/model.py", line 785, in _store_value entity._values[self._name] = value AttributeError: 'Ad' object has no attribute '_values'The offending code
if self.current_user: logging.info('user:'+str(self.current_user)) ad.usr = self.current_user.key ad.putModel
class Ad(GeoModel, search.SearchableModel): primary_image = blobstore.BlobReferenceProperty() usr = ndb_model.KeyProperty() ...Is there a recommended way to do what I'm trying to do?
Thanks
最满意答案
NDB和db中的密钥类型不同。 您必须将NDB密钥(self.current_user.key)转换为db.Key实例,如下所示:
ad.usr = self.current_user.key.to_old_key()请参阅https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_to_old_key
The Key types in NDB and db are different. You must convert the NDB Key (self.current_user.key) to a db.Key instance as follows:
ad.usr = self.current_user.key.to_old_key()See https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_to_old_key
发布评论