BadValueError:属性xxxx是必需的,即使已经设置了xxxx属性? (谷歌应用程序引擎) [英] BadValueError: Property xxxx is required, even after the xxxx property has already been set? (google app engine)

查看:125
本文介绍了BadValueError:属性xxxx是必需的,即使已经设置了xxxx属性? (谷歌应用程序引擎)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的模型:

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()

和我的处理程序:

and my handler:

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()

我的问题是,我已经设置了所需的属性,为什么在浏览器中加载它时仍然出现这个错误:

My question is, I already set the required properties, why do I still get this error when loaded it in the browser:

Traceback最后):
通话中的第700行文件/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/webapp/init.py
handler.get(* groups)
文件/home/wliao/Programming/MysteryLeague/src/controllers/test.py,第8行,获取
create(100)
Fi le/home/wliao/Programming/MysteryLeague/src/controllers/test.py,第18行,创建
article = models.model.Article()
文件/ home / wliao / Programming /GoogleAppEngineSDK/google/appengine/ext/db/init.py,第910行,位于 init
道具中。 set ( self,value)
set 中的文件/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py,第594行>
value = self.validate(value)
文件/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行,验证
引发BadValueError('属性%s是必需的'%self.name)
BadValueError:属性内容是必需的

Traceback (most recent call last): File "/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/webapp/init.py", line 700, in call handler.get(*groups) File "/home/wliao/Programming/MysteryLeague/src/controllers/test.py", line 8, in get create(100) File "/home/wliao/Programming/MysteryLeague/src/controllers/test.py", line 18, in create article = models.model.Article() File "/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py", line 910, in init prop.set(self, value) File "/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py", line 594, in set value = self.validate(value) File "/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py", line 2627, in validate value = super(UnindexedProperty, self).validate(value) File "/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py", line 621, in validate raise BadValueError('Property %s is required' % self.name) BadValueError: Property content is required

谢谢!

Thanks!

推荐答案

通过文档
$ b

From the docs:


由于构建
实例时发生验证,因此配置为必需的任何属性
必须为
在构造函数中初始化。

Because validation occurs when the instance is constructed, any property that is configured to be required must be initialized in the constructor.

所以:

So:

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)

这篇关于BadValueError:属性xxxx是必需的,即使已经设置了xxxx属性? (谷歌应用程序引擎)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆