views:

197

answers:

2

Hi, 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)
+1  A: 

I think this should work:

def setVenueIntroText(text):
  query = db.GqlQuery("SELECT * FROM Venue")
  for result in query:
    result.intro_text = text
    db.put(result)
Jeremy Stanley
I get the same result with this. my error message always tells me <class 'django.template.TemplateDoesNotExist'> - but I think this is masking the real exception.....grrrr....
Louis Sayers
I just deleted the temporary datastore and history, and tried this code again, and it worked - thanks :)
Louis Sayers
+1  A: 

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.

Louis Sayers