Juha Tuomala
Juha Tuomala

Reputation: 111

How to catch Cheetah NameMapper.NotFound exception?

I've a piece of code:

                #try:
                    <a href="/organisations/details/?tag=$inv.customer.org.tag">$inv.customer.org.name</a>
                #except NameMapper.NotFound
                    #try:
                        $inv.customer.person.firstname $inv.customer.person.lastname
                    #except NotFound
                        n/a
                    #end try
                #end try

And it raises:

<type 'exceptions.NameError'>:global name 'NameMapper' is not defined
  File "/usr/lib64/python2.7/site-packages/modweb/wsgi/main.py", line 139, in application
     responseBody = str(pageTemplate)
  File "/usr/lib64/python2.7/site-packages/Cheetah/Template.py", line 1005, in __str__
   rc = getattr(self, mainMethName)()
  File "/srv/www/template.py", line 1
  ...

Page https://pythonhosted.org/Cheetah/users_guide/errorHandling.html

uses it similar way, but i've no idea - do I have to import that exception class from somewhere?

There is a lot of talk about C-version of the same _namepper.so lib, but this is not related to that faster version of this same NameMapper -class, I would be a win whatever works finally.

Upvotes: 1

Views: 497

Answers (1)

Juha Tuomala
Juha Tuomala

Reputation: 111

Right, it needs to be defined at the same page that template code is defined, having it in global chainloaded templates won't work.

#from Cheetah import NameMapper

fixes the issue.

Upvotes: 1

Related Questions