App Engine - 尝试设置模型属性值时出现问题
我对应用程序引擎还很陌生,我第一次尝试在应用程序引擎数据库中设置一些文本。
这是我的代码:
def setVenueIntroText(text):
venue_obj = db.GqlQuery("SELECT * FROM Venue").get()
venue_obj.intro_text = text # Works if I comment out
db.put(venue_obj) # These two lines
这会引发某种异常 - 由于我的 django 1.02 设置,我无法说出它是什么。
好的,我在下面的答案中给出了代码,它在删除我的数据存储后起作用了,但我仍然不满意。
这是一个更新:
我已将代码修改为看起来对我有意义的内容。 当我调用 getVenueIntroText 时,它不会抱怨 - 顺便说一句,我在数据库中没有任何项目。
当我调用 setVenueIntroText 时,由于某种原因它不喜欢我正在做的事情 - 如果有人知道原因,我真的很想知道:)
这是我最新的尝试:
def getVenueIntroText():
venue_info = ""
venue_obj = db.GqlQuery("SELECT * FROM Venue").get()
if venue_obj is not None:
venue_info = venue_obj.intro_text
return venue_info
def setVenueIntroText(text):
venue_obj = db.GqlQuery("SELECT * FROM Venue").get()
if venue_obj is None:
venue_obj = Venue(intro_text = text)
else:
venue_obj.intro_text = text
db.put(venue_obj)
I'm pretty new to app engine, and I'm trying to set a bit of text into the app engine database for the first time.
Here's my code:
def setVenueIntroText(text):
venue_obj = db.GqlQuery("SELECT * FROM Venue").get()
venue_obj.intro_text = text # Works if I comment out
db.put(venue_obj) # These two lines
This throws some sort of exception - I can't tell what it is though because of my django 1.02 setup.
Ok, I gave the code in the answer below a go, and it worked after deleting my datastores, but I'm still not satisfied.
Here's an update:
I've modified my code to something that looks like it makes sense to me. The getVenueIntroText doesn't complain when I call it - I haven't got any items in the database btw.
When I call setVenueIntroText, it doesn't like what I'm doing for some reason - if someone knows the reason why, I'd really like to know :)
Here's my latest attempt:
def getVenueIntroText():
venue_info = ""
venue_obj = db.GqlQuery("SELECT * FROM Venue").get()
if venue_obj is not None:
venue_info = venue_obj.intro_text
return venue_info
def setVenueIntroText(text):
venue_obj = db.GqlQuery("SELECT * FROM Venue").get()
if venue_obj is None:
venue_obj = Venue(intro_text = text)
else:
venue_obj.intro_text = text
db.put(venue_obj)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这应该有效:
I think this should work:
我认为主要问题是我看不到错误消息 - 我真的很愚蠢,我忘记将 DEBUG = True 放入我的settings.py
事实证明我需要在我的 StringProperty 中使用 multiline=True
Django 正在捕获我的异常为我。
I think the main problem was that I couldn't see the error messages - really stupid of me, I forgot to put DEBUG = True in my settings.py
It turns out I needed a multiline=True in my StringProperty
Django is catching my exceptions for me.