$inv.customer.org.name #except NameMapper.NotFound #try: $" /> $inv.customer.org.name #except NameMapper.NotFound #try: $" /> $inv.customer.org.name #except NameMapper.NotFound #try: $"/>

How to catch Cheetah NameMapper.NotFound exception?

470 Views Asked by At

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.

1

There are 1 best solutions below

0
Juha Tuomala On

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.