views:

22

answers:

1

I got the following very basic template:

<html>
<head>
</head>
<body>

<div>
<!-- Using "for" to iterate through potential pages would prevent getting empty strings even if only one page is returned because the "page" is not equal the query, it is a subcomponent of the query -->
<div>{{ page.name }}</div>
<div>{{ page.leftText }}</div>
<div>{{ page.imageURL }}</div>
<div>{{ page.rightText }}</div>
</div>

</body>
</html>

And the very basic Model:

class Page(db.Model):
 name = db.StringProperty(required=True)
 leftText = db.TextProperty()
 rightText = db.TextProperty()
 imageURL = db.LinkProperty()

And the very basic Handlers:

class BaseRequestHandler(webapp.RequestHandler):
    #######
class PageContentLoadRequestHandler(BaseRequestHandler):

 def renderPage(self, values):
  directory = os.path.dirname(__file__)
  path = os.path.join(directory, 'templates', 'simple_page.html')
  return template.render(path, values, True)

 def get(self):
  page = db.get('aghwc21vZWJlbHIKCxIEUGFnZRgBDA')
            #alternative code
            # page db.get(db.key(self.request.get('key')))
            # The solution is to call/fetch the wanted object/query
  data = page.get() # or ... = Page.gql("GQL CODE").fetch(1)
  values = {'page': page}
  template_name = "simple_page.html"
  return self.response.out.write(self.renderPage(values))

The key is just randomly taken out of my storage, it is a real existing key of a filled entity. They idea is to load a page content dynamically into the doc via AJAX, problem is, that this handler returns an empty template. No ERRORS, 200 HTTP Code, key exists etc, etc, etc. I am totally broken and a bit annoyed, by such problems, because I quiet do not know where the fault could be.

regards,

EDIT: Changing the template values to there correct names, I now get the following erro:

    values = {'page': page, 'name': page.name,}
AttributeError: 'NoneType' object has no attribute 'name'
+2  A: 

Your properties are called 'leftText', 'rightText', and 'imageURL', but you're trying to print out 'left_text', 'right_text' and 'image_url'. Django, in its infinite wisdom, simply returns an empty string when you try to access a property that doesn't exist, rather than throwing an exception.

Nick Johnson
I get a "new" error see above.
daemonfire300
Your new problem is caused by `page` being `None` at that point in the code, meaning you're not actually getting a `Page` back from your `db.get()` call.
Jason Hall
Finally I got the whole thing, I think I wasn't concentrated enough and stumbled upon more or less "typos" and smaller structure mistakes.Thanks for your support.
daemonfire300