我不确定我做错了什么,如果您能指出我要阅读的内容,那就太好了。我在第一个 CherryPy 教程“hello world”中添加了一点 matplotlib 情节。问题1:我怎么知道文件将保存在哪里?它恰好是我运行文件的地方。问题 2:我似乎无法在浏览器中打开/查看图像。当我在浏览器中查看源代码时,一切看起来都是正确的,但没有运气,即使我包含了完整的图像路径。我认为我的问题在于路径,但不确定正在发生的事情的机制
感谢文森特的帮助
import cherrypy
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
class HelloWorld:
def index(self):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])
fig.savefig('test.png')
return ''' <img src="test.png" width="640" height="480" border="0" /> '''
index.exposed = True
import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld(), config=tutconf)
else:
cherrypy.tree.mount(HelloWorld(), config=tutconf)