【发布时间】:2015-03-08 11:24:28
【问题描述】:
我正在将 CherryPy 与 Python 一起使用,而且我对这一切都很陌生。最终我也会使用 JQuery,所以按照网上的一个例子,我有下面的内容,它正确地调用了 html。
我的问题是,虽然它调用了我的 html,但我不确定如何处理我的 CSS 和图像。我已经尝试从 html 中正常调用它们,但我没有任何运气。
def index(self):
return file('index.html')
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/generator': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')],
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './public'
}
}
webapp = StringGenerator()
webapp.generator = StringGeneratorWebService()
cherrypy.quickstart(webapp, '/', conf)
在我的 html 中,我有正常的 <link href="/static/css/style2.css" rel="stylesheet">,但它不起作用。
我的文件结构是 - public 和 css 是一个文件夹:
fitbit.py fitbit.html - 上市 -CSS style2.css
所以它正确调用了 fitbit.html,但在 html 中,我无法获取 css 和图像。任何有关如何调用它的帮助将不胜感激。
【问题讨论】: