atom feed1 message in com.googlegroups.turbogears[TurboGears] Re: 500 Error when using...
FromSent OnAttachments
wesley chunJul 21, 2008 5:36 pm 
Subject:[TurboGears] Re: 500 Error when using Mako as a templating engine
From:wesley chun (wes@gmail.com)
Date:Jul 21, 2008 5:36:26 pm
List:com.googlegroups.turbogears

just in case anyone has these problems switching from Kid to Mako and are searching the archives...

1. the Mako code is fixed now, so you can have just one single directory in the mako.directories list. for example, my app.cfg now has: : mako.directories=['templates'] :

2. another problem that people have is that in your controller, your @expose decorator call tends to have more of a "full-path" to the template when porting from Kid, i.e.,

@expose(template="tghello.templates.hello") def hello(self): :

when switching to Mako, because of your mako.directories list, you no longer have to give the entire path, meaning that the failures are happening because it's trying to find that full name as a template file name, which isn't going to work. so for my example above, visiting http://localhost:8080/hello still fails with the same error, and it wasn't until i changed my @expose() argument to the below that i got it to work:

@expose(template="hello") def hello(self): :

hope this helps someone eventually! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com

On Jan 10, 7:00 am, "qazu@gmail.com" <qazu@gmail.com> wrote:

Figured it out.

mako.directories in app.cfg MUST have more then one directory in it.

The bug lies in Mako's code, sometimes the directories property is treated as a list with more then one string in it, sometimes it is treated as a list with any number of strings in it.

On Jan 9, 3:22 pm, "qazu@gmail.com" <qazu@gmail.com> wrote:

I did an "easy_install mako" on a Windows machine with TG already installed and working.

My code for my controllers.py is simply: from turbogears import controllers, expose, flash from turbogears importidentity, redirect from cherrypy import request, response

class Root(controllers.RootController): @expose(template="mako:makotest.templates.test") def index(self): return dict()

There is a file makotest\templates\test.mak. When I do python start- makotest.py, everything runs ok until I connect and then I get the following traceback:

500 Internal error The server encountered an unexpected condition which prevented it from fulfilling the request.

Page handler: <bound method Root.index of <smqt.controllers.Root object at 0x01391B10>> Traceback (most recent call last): File "c:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy \_cphttptools.py", line 105, in _run self.main() File "c:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy \_cphttptools.py", line 254, in main body = page_handler(*virtual_path, **self.params) File "<string>", line 3, in index File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg \turbogears\controllers.py", line 344, in expose *args, **kw) File "<string>", line 5, in run_with_transaction File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg \turbogears\database.py", line 312, in so_rwt retval = func(*args, **kw) File "<string>", line 5, in _expose File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg \turbogears\controllers.py", line 359, in <lambda> mapping, fragment, args, kw))) File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg \turbogears\controllers.py", line 399, in _execute_func return _process_output(output, template, format, content_type, mapping, fragment) File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg \turbogears\controllers.py", line 86, in _process_output fragment=fragment) File "C:\Python25\lib\site-packages\turbogears-1.0.3.2-py2.5.egg \turbogears\view\base.py", line 129, in render return engine.render(**kw) File "C:\Python25\lib\site-packages\mako-0.1.10-py2.5.egg\mako\ext \turbogears.py", line 48, in render template = self.load_template(template) File "C:\Python25\lib\site-packages\mako-0.1.10-py2.5.egg\mako\ext \turbogears.py", line 44, in load_template return self.lookup.get_template(templatename) File "c:\python25\lib\site-packages\mako-0.1.10-py2.5.egg\mako \lookup.py", line 72, in get_template raise exceptions.TopLevelLookupException("Cant locate template for uri '%s'" % uri) TopLevelLookupException: Cant locate template for uri '/smqt/templates/ test.mak' Powered by CherryPy 2.2.1

When I googled the error I found some posts to this mailing list dated Jan 07 that described my problem, but also mentioned that the fix for it had been committed, and that everything should work if I set mako.directories to my template directory in my config file.

So I put mako.directories="makotest.templates" in my app.cfg, and still a 500 error. I tried mako.directories="makotest/templates", mako.directories="makotest\templates" all without luck.

I'm positive I'm not the only one to ever tread down this road. Does anyone know what I need to do to get mako to render templates without throwing 500 at me every time? Thank you.