Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/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 实体存在,返回空模板_Python_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Python 实体存在,返回空模板

Python 实体存在,返回空模板,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,我得到了以下非常基本的模板: <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, i

我得到了以下非常基本的模板:

<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>
最基本的处理程序是:

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))
密钥只是随机从我的存储中取出的,它是一个填充实体的真实现有密钥。 他们的想法是通过AJAX将页面内容动态加载到文档中,问题是,该处理程序返回一个空模板。 无错误、200 HTTP代码、密钥存在等。 我完全崩溃了,有点恼火,这些问题,因为我不知道哪里可能是故障

问候,

编辑:将模板值更改为正确的名称,我现在得到以下错误:

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

您的属性称为“leftText”、“rightText”和“imageURL”,但您正在尝试打印“leftText”、“rightText”和“imageURL”。Django以其无穷的智慧,在您尝试访问不存在的属性时,只返回一个空字符串,而不是抛出异常。

您的新问题是由
page
在代码中的该点处为
None
引起的,这意味着您实际上没有从
db.get()获得
page
call。最后,我明白了所有的事情,我觉得我不够专注,或多或少地遇到了“打字错误”和较小的结构错误。谢谢你的支持。
    values = {'page': page, 'name': page.name,}
AttributeError: 'NoneType' object has no attribute 'name'