Tornado NameError: global name ‘modules’ is not defined

Very Geeky Post ahead.

If you’re using Tornado and playing with UI Modules, you might see the message above. Haveing spent a couple of hours on this, I thought it would be worthwhile to pass on what I learned:

Here’s what I was doing:


template = config.templateLoader.load('upload_model.html')
self.write(template.generate(avatar=memberName, errorMessage=None, createUrl=createUrl, cmn=cmn))

Where “config.templateLoader” is the Tornado template loader.

The problem is that template.generate doesn’t pass the list of UI Modules to the template, which gives you the error.

Here’s the solution, recode as follows:


self.render('lupload_model.html', memberName=memberName, errorMessage=None, createUrl=createUrl, cmn=cmn)

Oh, one other nice thing, it you include “debug=”yes” in the Tornado HTTPServer settings, it will automatically reload templates and handlers for each request.

And that’s it for my tornado tips for today.

Advertisements
  1. Leave a comment

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

%d bloggers like this: