"无效数值错误:属性 xxxx 是必须的,即使 xxxx 属性已经被设置?(谷歌应用引擎)"

2024-09-30 22:22:25 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的模型:

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

我的处理者:

^{pr2}$

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

回溯(最近一次呼叫): File“/home/wliao/Programming/google/appengine/ext/webapp/init.py”,第700行,在call 处理程序.get(*组) 文件“/home/wliao/Programming/MysteryLeague/src/controllers”/测试.py“,第8行,在get中 创建(100) 文件“/home/wliao/Programming/MysteryLeague/src/controllers”/测试.py“,第18行,在create中 条款=模型.模型.文章() File“/home/wliao/Programming/google/appengine/ext/db/init.py”,第910行,在init 属性设置(自身,值) File“/home/wliao/Programming/google/appengine/ext/db/init.py”,第594行,在set 值=自我验证(值) 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py”,validate中的第2627行 value=super(unindex属性,self)。验证(value) 文件“/home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init.py”,validate中的第621行 raise BadValueError('需要属性%s'%自身名称) BadValueError:属性内容是必需的

谢谢!在


Tags: 文件py模型truehomedb属性init
1条回答
网友
1楼 · 发布于 2024-09-30 22:22:25

来自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)

相关问题 更多 >