0
我打算使用Cherrypy爲一個網站,但我有一些問題與映射我想要顯示的功能在Python代碼頁面的網址。Cherrypy映射網址到功能
現在我有這樣的代碼
#!/usr/bin/env python
import os
localDir = os.path.dirname(__file__)
absDir = os.path.join(os.getcwd(), localDir)
import cherrypy
from genshi.template import TemplateLoader
loader = TemplateLoader('../html', auto_reload=True)
class Root(object):
@cherrypy.expose
def index(self):
tmpl = loader.load('index.html')
return tmpl.generate().render('html', doctype='html')
@cherrypy.expose
def upload(self, datafile):
#do something
...
return out % (size, datafile.filename, datafile.content_type)
cherrypy.root.index = index
cherrypy.root.upload = upload
conf = os.path.join(os.path.dirname(__file__), 'server.config')
cherrypy.quickstart(Root(), '/', config=conf)
和配置文件是這樣的:
[/index.html]
tools.staticfile.on = True
tools.staticfile.filename = "/path-to-file/html/index.html"
[/impemails.html]
tools.staticfile.on = True
tools.staticfile.filename = "/path-to-file/html/impemails.html"
[/css/style.css]
tools.staticfile.on = True
tools.staticfile.filename = "/path-to-file/css/style.css"
[/css/index.css]
tools.staticfile.on = True
tools.staticfile.filename = "/path-to-file/css/index.css"
[/css/imp.css]
tools.staticfile.on = True
tools.staticfile.filename = "/path-to-file/css/imp.css"
對於配置文件沒有問題,指定的所有文件,但是當我嘗試訪問與鏈接上傳http://localhost:8080/upload我收到「404未找到消息」
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/local/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/cherrypy/_cperror.py", line 386, in __call__
raise self
NotFound: (404, "The path '/upload' was not found.")
我嘗試了很多不同的方法來解決這個問題,如教程所示,但我失敗了。 我想我錯過了本教程中未報告的一些配置。
任何人作爲一些想法?
謝謝你提前