Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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 app engine中更改字典的键-使用不同的方法解决_Python_Google App Engine_App Engine Ndb - Fatal编程技术网

Python 在google app engine中更改字典的键-使用不同的方法解决

Python 在google app engine中更改字典的键-使用不同的方法解决,python,google-app-engine,app-engine-ndb,Python,Google App Engine,App Engine Ndb,将键值更改为字典值时遇到问题 def get(self): #Get all the Subjects subjects = ndb.gql('SELECT name,order FROM Subject ORDER BY order ASC') values = {'subjects':subjects} #Get all the Contents for subject in subjects: contents = ndb.gql('SELECT * FRO

将键值更改为字典值时遇到问题

def get(self):

  #Get all the Subjects
  subjects = ndb.gql('SELECT name,order FROM Subject ORDER BY order ASC')
  values = {'subjects':subjects}

  #Get all the Contents
  for subject in subjects:
    contents = ndb.gql('SELECT * FROM Content WHERE ANCESTOR IS :1 ORDER BY order ASC',subject.key)
    values[subject.name] = contents #***HERE is the issue***
而不是拿字典

value={key:value}

我正试着去

value={{key:value}:value}

提前感谢您的建议


编辑: 当我尝试

值['subject':subject.name]=内容

我得到了错误

TypeError:不可损坏的类型


已解决:采用不同的方法:

def get(self):
  #Get all the Subjects
  subjects = ndb.gql('SELECT name,order FROM Subject ORDER BY order ASC')
  values = {'subjects':subjects}
  #Get all the Contents
  values['contents'] = []
  for subject in subjects:
    #Formatting HTML output
    subjectAll = subject.name + ' ' + subject.order
    contents = ndb.gql('SELECT name,order FROM Content WHERE ANCESTOR IS :1 ORDER BY order ASC',subject.key)
    values['contents'].append(subjectAll)
    for content in contents:
      #Formatting HTML output
      contentAll = content.name + '  ' + content.order
      values['contents'].append(contentAll)

事实上,我刚刚找到了一个不同的解决方案。我发现在main.py中为HTML格式化数据并将其发送到HTML更容易,而不是用HTML格式化数据。像我使用替代方法那样用python脚本格式化HTML,而不是用实际的HTML,这通常是好的还是坏的做法???