Tornado – Static File Handler


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

Advertisements

2 thoughts on “Tornado – Static File Handler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s