【发布时间】:2018-02-22 03:51:36
【问题描述】:
代码:::
from bottle import route, request, response, template,run
import petl as etl
@route('/loc')
def abc():
response.headers['Access-Control-Allow-Origin']='*'
response.headers['Content-type']='application/json'
post = request.query.postcode
locationTable = etl.fromcsv('clinic_locations.csv')
abcd = etl.search(locationTable, 'Postcode', post)
return template('{{postcode}}',postcode=abcd)
这是csv 文件,我想以 json 格式获取结果,但我不知道该怎么做,因为我对 petl 和 bottle 框架非常陌生 当用户在浏览器上输入网址时,例如“localhost:8080/loc?postcode=4700”,它将返回有关该邮政编码的数据,但以 csv 格式返回,但我想以 json 格式获取输出,以便我可以使用这些数据在地图上找到地址 谁能帮我得到结果
示例:通过瓶子框架运行 localhost 后,我希望在浏览器上的输出是:
【问题讨论】:
-
你能分享一下你的输出现在是什么样子吗?
-
只是让您知道,缩进在 Python 中很重要。
-
是的,我知道我想得到 json 格式的输出,你能帮帮我吗
-
@NitikeshDubey etl 模块是什么?请给minimal, complete, and verifiable 答复。
-
更新了问题!!