python: serialize a dictionary into a simple html output

前端 未结 9 776
轮回少年
轮回少年 2021-01-12 00:59

using app engine - yes i know all about django templates and other template engines.

Lets say i have a dictionary or a simple object, i dont know its structure and i

9条回答
  •  不要未来只要你来
    2021-01-12 01:36

    imagine we have this :{name: "a", children:[{name: "b", children: [] },{..},{..}]

    def ConvertDictToUlLi():
        jsonResult = GetSomeRecursiveDict()
    
        def CreateHtml(DictItem, output):
            output = "
  • "+DictItem["name"] if jsonResult.has_key("name") else " " if len(DictItem["children"]) > 0: output = output + "
      " for item in DictItem["children"]: output = output + " "+CreateHtml(item, output)+" " output = output + "
    " return output+"
  • " result = "
      "+CreateHtml(jsonResult, "")+"
    " return result

提交回复
热议问题