我试图以StaticFileHandler
这样一种方式进行扩展,即我可以处理文件请求但调用self.render(filename, **kwargs)
文件以实际将其提供给客户端。(是的,我意识到那时它本身不再是静态文件)。
这是我要运行的代码:
class MustacheFileHandler(tornado.web.StaticFileHandler):
def get(self, filename):
self.render(_STATIC_ROOT_ + '/' + path.split('/')[len(path.split('/'))-2], userLoginStatus='you are logged out!')
# ...
class Application(tornado.web.Application):
def __init__(self, **overrides):
handlers = [(r'/(.*)', MustacheFileHandler, {'path' : _STATIC_ROOT_})]
# ...
..._STATIC_ROOT_
启动时加载的服务器配置文件中包含的变量在哪里。
我遇到的问题是,每当我尝试对GET
我知道服务器上存在的文件执行操作时,都会收到以下错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1332, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "myfile.py", line 173, in get
self.render(_STATIC_ROOT_ + '/' + path.split('/')[len(path.split('/'))-2], userLoginStatus='you are logged out!')
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 747, in render
self.finish(html)
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 877, in finish
self.set_etag_header()
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1257, in set_etag_header
etag = self.compute_etag()
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 2185, in compute_etag
version_hash = self._get_cached_version(self.absolute_path)
AttributeError: 'MustacheFileHandler' object has no attribute 'absolute_path'
我不确定是什么导致了此错误或如何处理它。