Hi,

I'm trying to store Mako templates in database and render them, but can't do
it in smart way.
Would you please give me advises ?

My apploach is following.

# my controller
class PageController(object):
  def show(self, id):
    page = PageModel.query.get_by(id=id)
    if not page:
      abort(404)

    from pylons import buffet
    from mako.template import Template
    mako_config = buffet.engines.get('mako')
    if not mako_config:
      raise Exception("mako engine not found.")
    namespace = {}
    namespace = buffet._update_names(namespace)

    template = Template(page.content, lookup=mako_config['engine'].lookup)
    return template.render_unicode(**namespace).encode('utf8', 'replace')


# Actually, I want to write like this, 
# but lookup options would not be passed to template with this approach.
class PageController(object):
  def show(self, id):
    page = PageModel.query.get_by(id=id)
    if not page:
      abort(404)

    from pylons import buffet
-    from mako.template import Template
    mako_config = buffet.engines.get('mako')
    if not mako_config:
      raise Exception("mako engine not found.")
    namespace = {}
    namespace = buffet._update_names(namespace)

-    template = Template(page.content, lookup=mako_config['engine'].lookup)
+    template = mako_config['engine'].load_template(
+                  templatename=None, template_string=page.template.content)
    return template.render_unicode(**namespace).encode('utf8', 'replace')


My questions are following.

1. Are there any good way to render templates, stored in database ?
2. I'm thinking of replacing mako engine "mako.ext.turbogears:TGPlugin" to
another.
   To do so, "python.templating.engines" should be overwritten.
   Are there any good way to overwrite entry points ?
3. I want to avoid using private method 'buffet._update_names', 
   are there any another recommended way ?

Thanks in advance.

----
Junya HAYASHI


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to