I am developing a simple web application with Tornado. It serves some dynamic files and some static. Dynamic problems are not a problem, but it is difficult for me to maintain a static file. What I want to do is to serve the /path/to/foo.json file when accessing the / foo.json url.
Note that /path/to/foo.json is outside the document root. In Apache, I would just create an alias. With Tornado, I have:
app = tornado.web.Application([ (r'/dynamic\.html', MyService, dict(param = 12345)), (r'/(foo\.json)', tornado.web.StaticFileHandler, {'path': '/path/to/foo.json'}) ])
I added a regex group operator () to satisfy Tornado, which would otherwise throw an exception. But now, when I access /foo.json, I get 404: File not found.
Tests show that Tornado is trying to use the path provided as the root directory to which it adds foo.json, implying that my file can be found if it is in /path/to/foo.json/foo.json. Close, but not quite.
I suppose I could shorten my path to a simple "/ path / to" that will fetch /path/to/foo.json at URL / foo.json, but this forces me to use the same name in the URL address, as in the file system. How can I just make a simple, arbitrary URL to map files to?
I did some research on this subject by reading the documentation for tornado.web.Application and tornado.web.StaticFilehandler , as well as some other qaru.site/questions/808743 / ... questions . Nothing is a perfectly appropriate case.
python tornado static-files
Randall cook
source share