Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数据库上的google应用程序引擎stringlist属性_Python_Google App Engine - Fatal编程技术网

Python 数据库上的google应用程序引擎stringlist属性

Python 数据库上的google应用程序引擎stringlist属性,python,google-app-engine,Python,Google App Engine,我想在google app engine中创建一个具有以下属性的数据库 class Questions(db.Model): title = db.StringProperty() author = db.StringProperty() text = db.TextProperty() date = db.DateProperty(auto_now_add = True) votes = db.IntegerProperty() answers

我想在google app engine中创建一个具有以下属性的数据库

class Questions(db.Model):
    title = db.StringProperty()
    author = db.StringProperty()
    text = db.TextProperty()
    date = db.DateProperty(auto_now_add = True)
    votes = db.IntegerProperty()
    answers = db.StringListProperty()
    tags = db.StringProperty()
问题是,当我转到仪表板并尝试从那里创建实体时,answers属性不在那里

有没有更好的方法来创建字符串列表,这样我就可以单独操作它们了

更新:

当我尝试更新实体并在字符串列表中添加内容时:

链接是localhost:9082/questions-4889528208719872

class QuestionPageHandler(BaseHandler):
    def get(self, *a, **kw):
        sURL = self.request.url.split("-")
        question = Questions.get_by_id(long(sURL[-1]))
        self.render_content("questionpage.html",question=question)

    def post(self, *a, **kw):
        answer = self.request.get("answer")
        sURL = self.request.url.split("-")
        question = Questions.get_by_id(long(sURL[-1]))
        question.answers.append(answer)
        question.put()  **<---- I forgot to add this EDIT**
class QuestionPageHandler(BaseHandler):
def get(自身,*a,**kw):
sURL=self.request.url.split(“-”)
问题=问题。通过id获取(长(sURL[-1]))
self.render_内容(“questionpage.html”,question=question)
def柱(自身,*a,**kw):
答案=self.request.get(“答案”)
sURL=self.request.url.split(“-”)
问题=问题。通过id获取(长(sURL[-1]))
问题.答案.附加(答案)
问题。解决方案:

def post(self, *a, **kw):
        answer = self.request.get("answer")
        sURL = self.request.url.split("-")
        question = Questions.get_by_id(long(sURL[-1]))
        question.answers.append(answer)
        **question.put()** <-- add this
def post(自身,*a,**kw):
答案=self.request.get(“答案”)
sURL=self.request.url.split(“-”)
问题=问题。通过id获取(长(sURL[-1]))
问题.答案.附加(答案)
**问题。放置()***

也许可以尝试具有列表类型属性的NDB

class Questions(db.Model):
    title = db.StringProperty()
    author = db.StringProperty()
    text = db.TextProperty()
    date = db.DateProperty(auto_now_add = True)
    votes = db.IntegerProperty()
    answers = db.StringListProperty()
    tags = db.StringProperty()
看->

ndb.StringProperty(重复=真) 或

ndb.StructuredProperty(xxx,repeated=True)

您将无法对最基本的类型使用数据存储查看器。我建议您使用远程api外壳或为您的应用程序编写一些代码。您能看到更新吗?谢谢你什么是BaseHandler。如果您使用webapp2,您通常会self.response.write self.render\u内容做什么,它是否会调用self.response.write?抱歉。我没提过。正是你说的。在呈现内容时,我称之为self.response.writeThank you Tim。我发现了问题所在。我编辑问题并添加解决方案。忘记添加“question.put()”