我一直在使用 CherryPy 3.2.2 测试 Twitter Bootstrap,并查看了一些 SO 帖子,但无法成功让 Cherry 使用我的配置文件运行。我收到了臭名昭著的 404 错误:“NotFound: (404, "The path '/' was not found.")”。
这是我的文件设置:
- /TwitApp(应用程序目录)
- testPy.py(我的测试应用程序)
- config.conf(添加 CSS 的配置文件)
- global.conf (服务器套接字、端口等的全局配置。我认为这可以放在 config.conf 中?)
- /css(CSS 文件夹)
- bootstrap.min.css
- /js(javascript 目录)
这是我的 testPy.py 代码:
#!/usr/bin/env python
import cherrypy
class HelloWorld:
def index(self):
return '''<!DOCTYPE html><html><head>
<title>Bootstrap Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
</head><body>
<h1>Bootstrap Test</h1>
<button type="button" class="btn">Submit</button>
</body></html>'''
index.exposed = True
#I tried this example that I found in the documentation and on previous posts with the same 404 result:
#cherrypy.quickstart(HelloWorld(), "/", "config.conf")
#I tried this one when I reviewed another post on here:
cherrypy.config.update("global.conf")
cherrypy.tree.mount(HelloWorld(),"/","config.conf")
cherrypy.engine.start()
cherrypy.engine.block()
在某一时刻,我的 global.conf 文件的 [global] 部分是我的 config.conf 文件的顶部,但是当我开始使用 mount、start 和 block 方法时,我将两者分开了。
这是我的 global.conf 文件:
[global]
server.socket_host = "127.0.0.1"
server.socket_port = 8080
log.screen: True
log.error_file: "/Users/myUser/tmp/newproject/cherrypy.error"
log.access_file: "/Users/myUser/tmp/newproject/cherrypy.access"
这是我的 config.conf 文件:
[/]
tools.staticfile.root = "/Users/myUser/tmp/newproject/TwitApp"
[/css/bootstrap.min.css]
tools.staticfile.on = True
tools.staticfile.filename = "css/bootstrap.min.css"
这是完整的错误消息:404 Not Found
The path '/' was not found.
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cperror.py", line 386, in __call__
raise self
NotFound: (404, "The path '/' was not found.")
我阅读最多的文章可以在这里找到:Cherrypy 返回 NotFound: (404, "The path '/' was not found.")和这里:Path Not Found in CherryPy。有人可以告诉我我做错了什么吗?