Trouble accessing favicon or css or other web page images with Tornado?

Well here’s the solution. Tornado provides tornado.web.StaticFileHandler construct that helps the web server locate images or icon files to be served while loading the web page. Here’s an example

In this example, articles.html is loading images/images.jpg. Path images/* is understood by Tornado with the statement

(r”/images/(.*)”,tornado.web.StaticFileHandler, {“path”: “./images”},),

What if, we make a slight change here, negation with ‘^’? This would mean, Tornado Web Server shouldn’t load anything under images directory. Convenient!

(r”/images/^(.*)”,tornado.web.StaticFileHandler, {“path”: “./images”},),

Please note you may face permission issues while loading content like .html, .css files. Ensure they have correct permissions to be accessed from Tornado