' Xml.etree.ElementTree.Element'到瓶子的模板如何交出来?

时间:2017-05-28 02:27:29

标签: python bottle

浏览器错误显示

 Error: 500 Internal Server Error Unsupported response type: <class
 Unsupported response type: <class 'xml.etree.ElementTree.Element'>

Apache错误日志

[error] [client ] TypeError: Object of type 'Element' is not JSON serializable
[error] [client ] TypeError: Object of type 'ElementTree' is not JSON serializable

我尝试过的代码,但我无法获得预期的结果

from xml.etree import ElementTree
from bottle import route, view

@route('/')
@view("hoge_template")
def hoge():
  tree = ElementTree.parse('rss-2.0.xml')
  root = tree.getroot()
  return(root)
  #return dict(root=root)

环境

·Python 3.6

·瓶0.13

·mod_wsgi的

·铬

如何在瓶子中显示循环的所有内容?

root = tree.getroot()
for item in root.findall('channel/item'):
    title = item.find('title').text
    url = item.find('link').text
    return(url, title)

0 个答案:

没有答案