Graham Dumpleton
grahamd at dscpl.com.au
Mon Mar 14 16:29:50 EST 2005
I somewhat suspect that you aren't going to get the code as by default generated by Cheetah to play well with publisher. As to your original custom handler, you could clean it up somewhat by using something like: start = "/python/" from mod_python import apache import string def handler(req): req.content_type = "text/html" module_name = string.replace (req.uri, start, "") # try: # exec ("""import %s #tmpl = %s.%s() #tmpl.req = req""" % (module_name, module_name, module_name)) # except ImportError: # return apache.HTTP_NOT_FOUND module = apache.import_module(module_name) if not hasattr(module,module_name): return apache.HTTP_NOT_FOUND tmpl = getattr(module,module_name)() tmpl.req = req req.send_http_header() req.write(tmpl.respond()) return apache.OK I still see some issues with this code in as much as I think it requires everything to be in the one directory. Ie., can't have subdirectories. Using "start" as a fixed value is not good, but that can also be fixed. Also, you can't mix different file types in the same directory. When I get a chance, I'll write you a better version of this which would fix these problems and provide new abilities as well. I am surprised though that someone hasn't already written a better handler for integrating Cheetah with mod_python. BTW, I am not on the Cheetah mailing list, so ensure any responses also go back to the mod_python list as well. Graham On Tuesday, March 15, 2005, at 02:17 AM, Stephane Bortzmeyer wrote: > I always used Cheetah on Apache with a custom mod_python handler (see > http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like to > use mod_python's publisher > http://www.modpython.org/live/current/doc-html/hand-pub.html, in order > to limit my liability :-) specially for security reasons. > > It works fine but not if I use Cheetah's inheritance, as described in > http://www.cheetahtemplate.org/docs/users_guide_html_multipage/ > inheritanceEtc.extends.html. > My foobar.tmpl Cheetah file is compiled as foobar.py, which includes a > foobar class. I added a index() routine but Cheetah puts in in the > foobar class, not directly in the foobar module. When > mod_python.publisher calls index(), it finds nothing and returns > NOT_FOUND. > > > > My SiteLogic.py: > > > from Cheetah.Template import Template > > class SiteLogic(Template): > """ Pure Python class containing methods for the site """ > > # Never found because Cheetah puts it in a class > def index(req): > return "Dummy" > > > > My Site.tmpl: > > > > #from SiteLogic import SiteLogic > #extends SiteLogic > #implements respond > > #def title > No title #slurp > #end def > > #def body > <P>Default body. > #end def > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> > <HTML> > <HEAD> > <TITLE> > $title > </TITLE> > </HEAD> > <BODY> > <H1>$title</H1> > $body > <HR> > > > > A typical page: > > > #from Site import Site > #extends Site > #implements body > #def title > Welcome > #end def > > <P>Some content. > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python
|