Super Hornet
Super Hornet

Reputation: 2907

Tornado does not show static files

I'm going to serve static files in Tornado. The following is the path of my project:

project/

   /app/app.py

   /static/css/<css files>

   /static/html/ <html files>

app.py:

def make_app():
    settings = {"static_path": os.path.join(os.path.dirname(__file__), "../static")}
    return tornado.web.Application([
        # (r"/", MainHandler),
        (r"/user/authenticate", AuthenticateHandler),
        (r"/user/getToken", TokenHandler),
        (r"/login", LoginPageHandler),
        (r"/(.*)", tornado.web.StaticFileHandler, {"path": html_root, "default_filename": "index.html"}),
        (r"/(.css)", tornado.web.StaticFileHandler,   dict(path=settings['static_path']))
    ])


if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

whenever I look for http://localhost:8888/somefile.min.css it returns 404

Upvotes: 1

Views: 368

Answers (1)

Ananth
Ananth

Reputation: 889

    (r"/(.*)", tornado.web.StaticFileHandler, {"path": html_root, "default_filename": "index.html"}),

This regex will match everything including your css files. So switch the last two entries around and it should work. Your catch-all regex is usually best placed at the end, as a catch-all should be.

Upvotes: 1

Related Questions