此查询有效:
item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = 13")[0]
Run Code Online (Sandbox Code Playgroud)
虽然如果没有结果返回,它会在我的脸上爆炸.(我怎样才能解决这个问题?for当我想要最多一次迭代时,一个循环看起来很可疑.)
此查询不起作用:
item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = :1", CSIN)[0]
Run Code Online (Sandbox Code Playgroud)
CSIN是一个表示数字的字符串.我收到此错误:
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 507, in __call__
handler.get(*groups)
File "path\to\src\Main.py", line 42, in get
item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = :1", CSIN)[0]
File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1717, in __getitem__
raise IndexError('The query returned fewer than %d results' % (arg+1))
IndexError: The query returned fewer …Run Code Online (Sandbox Code Playgroud) 我有持久对象,字符串属性通常超过500个字符.Google App Engine说我需要将其另存为com.google.appengine.api.datastore.Text.
如何将String类型转换为com.google.appengine.api.datastore.Text类型,以便我可以在属性上使用setMethod(),或者将我的长sting数据转换为该持久值?
如何在Google App Engine中创建数据库表
我能够插入,过滤和订购记录,但不能使用简单的计数!! 我想知道是否有办法在表中得到总行数?有没有办法在查询中使用GROUP BY?
如果我有一个从db.Expando派生的实体,我可以通过为新属性赋值来编写Dynamic属性,例如在这个例子中为"y":
class MyEntity(db.Expando):
x = db.IntegerProperty()
my_entity = MyEntity(x=1)
my_entity.y = 2
Run Code Online (Sandbox Code Playgroud)
但是假设我在变量中有动态属性的名称...我如何(1)读取和写入它,以及(2)检查实体的实例中是否存在动态变量?例如
class MyEntity(db.Expando):
x = db.IntegerProperty()
my_entity = MyEntity(x=1)
# choose a var name:
var_name = "z"
# assign a value to the Dynamic variable whose name is in var_name:
my_entity.property_by_name[var_name] = 2
# also, check if such a property esists
if my_entity.property_exists(var_name):
# read the value of the Dynamic property whose name is in var_name
print my_entity.property_by_name[var_name]
Run Code Online (Sandbox Code Playgroud)
谢谢...
python google-app-engine entity properties google-cloud-datastore
我有一个名为Version的Model,如下所示:
from google.appengine.ext import db
import piece
class Version(db.Model):
"A particular version of a piece of writing."
parent_piece = db.ReferenceProperty(piece.Piece, collection_name='versions')
"The Piece to which this version belongs."
note = db.TextProperty()
"A note from the Author about this version."
content = db.TextProperty()
"The actual content of this version of the Piece."
published_on = db.DateProperty(auto_now_add=True)
"The date on which the version was published."
Run Code Online (Sandbox Code Playgroud)
我想使用Version.get_by_id()通过其ID访问Version的实例,但此调用始终返回None.我可以在数据存储区查看器中看到它们具有ID值,在调试器中,我可以查询它们但不使用它们:
>>> for each_ver in version.Version.all():
... print each_ver.key().id()
...
34
35
36
31
32
>>> …Run Code Online (Sandbox Code Playgroud) 尝试将utf-8存储到数据存储区并获取错误:
Traceback (most recent call last):
File "/sinfo/google_appengine/google/appengine/ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/sinfo/siteinfo/siteinfo.py", line 1911, in get
seoEntity.put()
File "/sinfo/google_appengine/google/appengine/ext/db/__init__.py", line 833, in put
return datastore.Put(self._entity, rpc=rpc)
File "/sinfo/google_appengine/google/appengine/api/datastore.py", line 275, in Put
req.entity_list().extend([e._ToPb() for e in entities])
File "/sinfo/google_appengine/google/appengine/api/datastore.py", line 680, in _ToPb
properties = datastore_types.ToPropertyPb(name, values)
File "/sinfo/google_appengine/google/appengine/api/datastore_types.py", line 1499, in ToPropertyPb
pbvalue = pack_prop(name, v, pb.mutable_value())
File "/sinfo/google_appengine/google/appengine/api/datastore_types.py", line 1322, in PackString
pbvalue.set_stringvalue(unicode(value).encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not … 假设我有一个包含母,父和子对象的数据存储区.在母亲和父亲的对象里面,我有一个名为child的字段,它存储了对孩子的引用.是否有可能从母亲和父亲那里引用这个孩子而不为每个孩子创建重复的子实例(以OOP的方式).这是数据库的工作方式吗?
我正在谷歌应用程序引擎中开发一个具有用户配置文件类功能的应用程序.我正在浏览Google App的在线教程,我发现静态文件(应用程序文件和静态文件)的最大数量不应超过3000.我担心当用户数量增加时,用户是否可以上传他们的图像.这是免费配额的限制,还是在结算后.在文档中,它提到的附加限制比免费配额.
请建议.
提前致谢.
我想为我的GAE应用程序创建一个仅限管理员的页面.但我发现没有办法设置管理员用户,所以我无法登录我创建的页面并测试该功能.我尝试了本地管理控制台,但没有运气.我怎样才能做到这一点?