第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

tornado 模板加載一段json數(shù)據(jù)格式顯示問題

tornado 模板加載一段json數(shù)據(jù)格式顯示問題

米脂 2018-10-12 19:30:24
我在一個(gè)tornado應(yīng)用的handler中從mongodb中讀到了一個(gè)集合的所有文檔,將轉(zhuǎn)換成了json格式,然后我用這些json數(shù)據(jù)為傳入了tornado模板中,顯示在了瀏覽器中。handler的代碼是樣的:class MainHandler(BaseHandler):     def get(self):         codes = self.db.code.find()                 result = json.dumps(list(codes),              default=json_util.default,              sort_keys=True,              ensure_ascii=False,              indent=4)         print result         self.render('index.html', content = result)瀏覽器中顯示是這樣的:就是一個(gè)沒換行的狀態(tài)。在終端打印時(shí),卻又是換了行的:記得在django中,可以使用content.linebreaks來換行換行之類的,在tornado中,卻沒找到這種方法。煩請(qǐng)幫助一下。
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

dumps的時(shí)候,是不會(huì)加縮進(jìn)之類的。你的dumps指定了indent=4。

indent參數(shù)針對(duì)打印輸出時(shí)候的format

具體可以看文檔:

If indent is a non-negative integer (it is None by default), then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

還有一個(gè)比較好的工具,標(biāo)準(zhǔn)庫(kù)pprint用來print對(duì)象的時(shí)候顯示更美觀:


from?pprint?import?pprint
pprint(your_obj)


查看完整回答
反對(duì) 回復(fù) 2018-10-28
  • 1 回答
  • 0 關(guān)注
  • 1122 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)