wli*_*iao 5 python google-app-engine web-applications
这是我的模特:
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()
Run Code Online (Sandbox Code Playgroud)
和我的经纪人:
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()
Run Code Online (Sandbox Code Playgroud)
我的问题是,我已经设置了所需的属性,为什么在浏览器中加载时仍然会出现此错误:
回溯(最近一次调用最后一次):文件"/ home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/webapp/init .py",第700行,在call handler.get(*groups)文件中"/ home/wliao /Programming/MysteryLeague/src/controllers/test.py",第8行,在get create(100)文件中"/home/wliao/Programming/MysteryLeague/src/controllers/test.py",第18行,在create article = 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行,设置 值= self.validate(value)文件"/ home/wliao /编程/ GoogleAppEngineSDK/google/appengine/ext/db/init .py",第2627行,在验证值= super(UnindexedProperty,self).validate(value)文件"/ home/wliao/Programming/GoogleAppEngineSDK/google/appengine/ext/db/init .py",第621行,在validate中引发BadValueError('属性%s是必需'%self.name)BadValueError:属性内容是必需的
谢谢!
来自文档:
因为在构造实例时进行验证,所以必须在构造函数中初始化配置为必需的任何属性.
所以:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2668 次 |
| 最近记录: |