- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我的模型:
from google.appengine.ext import db
from google.appengine.ext.db import polymodel
class Item(polymodel.PolyModel):
title = db.StringProperty(required=True)
summary = db.StringProperty(required=True)
content = db.TextProperty(required=True)
createDate = db.DateTimeProperty(auto_now_add=True)
class Article(Item):
author = db.StringProperty()
和我的处理程序:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import models.model
class Test(webapp.RequestHandler):
def get(self):
create(100)
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Test')
self.response.out.write('<p>Created')
app = webapp.WSGIApplication([('/test/*', Test)], debug=True)
def create(count):
for i in range(0,count,1):
article = models.model.Article()
article.title = "Test title " + str(i)
article.author = "wliao"
article.summary = "this is a test " + str(i)
article.content = "this is the content of the article"
article.put()
def main():
run_wsgi_app(app)
if __name__ == "__main__":
main()
我的问题是,我已经设置了所需的属性,为什么在浏览器中加载它时仍然会出现此错误:
追溯(最近的调用最后): 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/webapp/init.py”,第 700 行,在 call handler.get(*组) 文件“/home/wliao/Programming/MysteryLeague/src/controllers/test.py”,第 8 行,在 get 创建(100) 创建文件“/home/wliao/Programming/MysteryLeague/src/controllers/test.py”,第 18 行 文章 = models.model.Article() 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py”,第 910 行,在 init prop.set( self , 值(value)) 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py”,第 594 行,在 set 中 值 = self.validate(值) 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py”,第 2627 行,在验证中 value = super(UnindexedProperty, self).validate(value) 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py”,第 621 行,在验证中 raise BadValueError('需要属性 %s' % self.name)BadValueError:需要属性内容
谢谢!
最佳答案
来自 the docs :
Because validation occurs when the instance is constructed, any property that is configured to be required must be initialized in the constructor.
所以:
title = "Test title " + str(i)
author = "wliao"
summary = "this is a test " + str(i)
content = "this is the content of the article"
article = models.model.Article(title=title, author=author,
summary=summary, content=content)
关于python - BadValueError : Property xxxx is required, 即使已经设置了 xxxx 属性? (谷歌应用引擎),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6142439/
我从 Google 应用引擎和验证器中获得了 ndb 模型。但是当我使用 postman 尝试验证并从 postman 生成的字符串中强制执行 int 时。我仍然收到 BadValueError:Ba
我试图通过使用将字符串转换为相应类型的 Key 的自定义验证器来简化 ndb KeyProperties 的 JSON 序列化和反序列化。 想法是拥有这样的属性: def key_validator(
我正在尝试删除数据存储中的记录。不幸的是,每当我尝试删除这些项目时,它都会给我一个 BadValueError,说 Districts(其中一列)是必需的。由于批量加载程序出现问题,所有行的 Dist
我正在使用 Python 创建 Google App Engine 应用程序。为了测试我的应用程序,我使用 html 表单输入数据。在我的表格中有一行: Age 在我的模型类中,属性定义如下: cla
这是我的模型: from google.appengine.ext import db from google.appengine.ext.db import polymodel class Item
bulkoader.yaml: transformers: - kind: ExampleModel connector: csv property_map:
GAE 快把我逼疯了。 我有以下内容: if id_puertas[x]: puerta = Puerta.get_by_id(int(id_puertas[x]))
我在本地运行 AppEngine。我对对象的以下属性使用了一些过滤器: class Blah(db.Model): access_code = db.StringProperty() 然后我在
我是一名优秀的程序员,十分优秀!