在CherryPy 3.1中提供静态文件时出现问题

2024-06-07 00:19:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我在为一个静态XML样式表提供服务时遇到了一些问题,这个静态XML样式表伴随着一个CherryPy web应用程序动态生成的输出。即使我的测试用例为静态文本文件服务也失败了。

静态文件blah.txt位于应用程序根目录中的/static目录中。

在我的主站点文件(conesearch.py包含CherryPy conesearch页面处理程序类)中:

import conesearch
cherrypy.config.update('site.config')
cherrypy.tree.mount(conesearch.ConeSearch(), "/ucac3", 'ucac3.config')
...

site.config中,我有以下选项:

[/]
tools.staticdir.root: conesearch.current_dir

[/static]
tools.staticdir.on: True
tools.staticdir.dir: 'static'

其中current_dir = os.path.dirname(os.path.abspath(__file__))conesearch.py

但是,我的简单测试页(直接从http://www.cherrypy.org/wiki/StaticContent获取)失败,出现404:

def test(self):
        return """
        <html> 
        <head>
        <title>CherryPy static tutorial</title>
        </head>
        <body>
        <a href="/static/blah.txt">Link</a>
        </body>
        </html>"""
test.exposed = True

它试图访问127.0.0.1:8080/static/blah.txt,据我估计应该是AOK。有什么想法或建议吗?

干杯

西蒙


Tags: 文件txtconfig应用程序dir静态staticxml