0
我正在构建一个bottle.py应用程序,它从MongoDB获取一些数据并使用pygal将其呈现到网页中。bottle.py渲染静态文件
该代码在我的浏览器中生成Error: 500 Internal Server Error
。
在服务器上,我看到:Exception: TypeError('serve_static() takes exactly 1 argument (0 given)',)
。
我的问题:我该如何纠正代码来渲染.svg
文件?
代码:
import sys
import bottle
from bottle import get, post, request, route, run, static_file
import pymongo
import json
import pygal
connection = pymongo.MongoClient("mongodb://localhost", safe=True)
@get('/chart')
def serve_static(chart):
db = connection.control
chart = db.chart
cursor = chart.find({}, {"num":1, "x":1, "_id":0})
data = []
for doc in cursor:
data.append(doc)
list = [int(i.get('x')) for i in data]
line = pygal.Line()
line.title = 'widget quality'
line.x_labels = map(str, range(1, 20))
line.add('quality measure', list)
line.render_to_file('chart.svg')
try:
return static_file(chart.svg, root='/home/johnk/Desktop/chart/',mimetype='image/svg+xml')
except:
return "<p>Yikes! Somethin' wrong!</p>"
bottle.debug(True)
bottle.run(host='localhost', port=8080)