I am developing a simple web app with Tornado. It serves some dynamic files and some static ones. The dynamic ones are not a problem, but I am having trouble serving a static fi
StaticFileHandler expects two arguments, so if you want a single url (/foo.json) to be mapped to your file path you can use:
app = tornado.web.Application([
(r'/foo.json()', tornado.web.StaticFileHandler, {'path': '/path/to/foo.json'})
])
The regex will match /foo.json
and send the empty capture group ()
, which will cause the filepath to be used as is. When the capture group is not empty, /path/to/foo.json
will be treated as a directory /path/to/foo.json/
, and the handler will try to match whatever is within the capture group to a file name in that directory.