【问题标题】:HTTP 404 while using tornado's StaticFileHandler class使用龙卷风的 StaticFileHandler 类时出现 HTTP 404
【发布时间】:2014-12-26 16:29:14
【问题描述】:

我在使用 tornado 的 StaticFileHandler 类时得到以下回溯。 追溯:

    Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1334, in _execute
    result = yield result
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 628, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 109, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 175, in wrapper
    yielded = next(result)
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 2110, in get
    self.root, absolute_path)
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 2286, in validate_absolute_path
    raise HTTPError(404)
HTTPError: HTTP 404: Not Found

这是我的目录结构:

服务器/

  • httpserver.py
  • 静态/静态/foo/bar/files.extension

httpserver.py 的内容:

settings = {
'debug': True,
'autoreload': True,
}

application = tornado.web.Application([\
            (r"/(.*)",tornado.web.StaticFileHandler,\
            {"path":"static/static/foo/bar/"}),],\
            **settings)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()

我已经经历了类似的问题,他们似乎没有给我一个合适的解决方案。

【问题讨论】:

  • 因为当您导入 httpserver 时,它会与您的文件 httpserver.py 发生冲突

标签: python python-2.7 tornado static-files


【解决方案1】:

我自己解决了这个问题。我添加了一个关键字参数 static_path,它是从根目录到 .py 文件所在目录的路径。更正后的工作代码:

settings = {
'debug': True,
'autoreload': True,
'static_path': '/home/path/to/pythonFile'
}

application = tornado.web.Application([\

            (r"(.*)",tornado.web.StaticFileHandler,\
            {"path":"static/foo/bar"}),],\
            **settings)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()

【讨论】:

  • 什么 .py 文件?我有这个确切的回溯。
  • httpserver.py 文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-14
相关资源
最近更新 更多