templating system

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ksenia Marasanova

    #1

    templating system

    Hi,

    I am looking for fast, simple templating system that will allow me to
    do the following:
    - embed Python code (or some templating code) in the template
    - generate text output (not only XML/HTML)

    I don't need a framework (already have it), but just simple
    templating. The syntax I had in mind is something like that:

    # in Python module
    def some_view():
    # some code goes here...
    records = get_some_data()
    req = get_request_cla ss()
    return template('some_ template.tmpl', **locals()).ren der()

    # in some_template.t mpl:

    <ul>
    <%for record in records%>
    <li><a href="<%=record .id%>"><%=recor d.title%></a></li>
    <%end for%>
    </ul>

    [color=blue]
    >From what I saw Cheetah seems to be the only one that can do it. I was[/color]
    hoping there might be alternatives that I've missed :)
    Thanks!

    --
    Ksenia
  • Erik Max Francis

    #2
    Re: templating system

    Ksenia Marasanova wrote:
    [color=blue]
    > I am looking for fast, simple templating system that will allow me to
    > do the following:
    > - embed Python code (or some templating code) in the template
    > - generate text output (not only XML/HTML)
    >
    > I don't need a framework (already have it), but just simple
    > templating. The syntax I had in mind is something like that:
    >
    > # in Python module
    > def some_view():
    > # some code goes here...
    > records = get_some_data()
    > req = get_request_cla ss()
    > return template('some_ template.tmpl', **locals()).ren der()
    >
    > # in some_template.t mpl:
    >
    > <ul>
    > <%for record in records%>
    > <li><a href="<%=record .id%>"><%=recor d.title%></a></li>
    > <%end for%>
    > </ul>
    >
    >[color=green]
    >>From what I saw Cheetah seems to be the only one that can do it. I was[/color]
    > hoping there might be alternatives that I've missed :)
    > Thanks![/color]

    EmPy will also do this quite handily:



    In EmPy, your template would look something like this::

    <ul>
    @[for record in records]@
    <li><a href="@record.i d">@record.titl e</a></li>
    @[end for]@
    </ul>

    Batch expanding the template would look like something as simple as
    (substituting in your example)::

    ...
    return em.expand(open( templateFilenam e).read(), **locals())

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
    There's this perfect girl / Someone no one can see
    -- Lamya

    Comment

    • Ron_Adam

      #3
      Re: templating system

      On Sun, 10 Apr 2005 17:55:06 +0200, Ksenia Marasanova
      <ksenia.marasan ova@gmail.com> wrote:
      [color=blue]
      >Hi,
      >
      >I am looking for fast, simple templating system that will allow me to
      >do the following:
      >- embed Python code (or some templating code) in the template
      >- generate text output (not only XML/HTML)
      >
      >I don't need a framework (already have it), but just simple
      >templating. The syntax I had in mind is something like that:
      >
      ># in Python module
      >def some_view():
      > # some code goes here...
      > records = get_some_data()
      > req = get_request_cla ss()
      > return template('some_ template.tmpl', **locals()).ren der()
      >
      ># in some_template.t mpl:
      >
      ><ul>
      ><%for record in records%>
      > <li><a href="<%=record .id%>"><%=recor d.title%></a></li>
      ><%end for%>
      ></ul>
      >
      >[color=green]
      >>From what I saw Cheetah seems to be the only one that can do it. I was[/color]
      >hoping there might be alternatives that I've missed :)
      >Thanks![/color]

      I use Cheetah along with publish.py by Chris Gonnerman. Cheetah
      constructs web pages using .html templates and a python script, (which
      is why I like it). Publish.py gives me fast one click publishing to
      the web server, adding or removing files from the server to match my
      local publish directory.

      Looks like Chris also has a templating program here as well. I
      haven't checked it out yet, so can't tell you about it.



      Cheers,
      Ron

      Comment

      • Ksenia Marasanova

        #4
        Re: templating system

        > In EmPy, your template would look something like this::[color=blue]
        >
        > <ul>
        > @[for record in records]@
        > <li><a href="@record.i d">@record.titl e</a></li>
        > @[end for]@
        > </ul>
        >
        > Batch expanding the template would look like something as simple as
        > (substituting in your example)::
        >
        > ...
        > return em.expand(open( templateFilenam e).read(), **locals())[/color]

        Thanks!

        I've read "Known issues and caveats" on the website:

        """
        EmPy was primarily intended for static processing of documents,
        rather than dynamic use, and hence speed of processing was not the
        primary consideration in its design.
        """

        Have you noticed any speed problems with EmPy?

        --
        Ksenia

        Comment

        • Erik Max Francis

          #5
          Re: templating system

          Ksenia Marasanova wrote:
          [color=blue]
          > Thanks!
          >
          > I've read "Known issues and caveats" on the website:
          >
          > """
          > EmPy was primarily intended for static processing of documents,
          > rather than dynamic use, and hence speed of processing was not the
          > primary consideration in its design.
          > """
          >
          > Have you noticed any speed problems with EmPy?[/color]

          In the interests of full disclosure, I'm the author of EmPy.

          All I meant by that note was that EmPy was not primarily designed for
          blazing speed; that is, it could easily be made much more efficient in a
          lot of ways. I've never had a need to do so, so it's always been low
          priority. I've certainly never heard of any complaints of EmPy's speed
          (or lack therefore) as being a problem in the field. Unless you huge
          realtime demands, I doubt EmPy's speed would be a major impediment. (Of
          course, if you find that it is, please tell me!)

          --
          Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
          San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
          A wise man never loses anything if he have himself.
          -- Montaigne

          Comment

          • Ksenia Marasanova

            #6
            Re: templating system

            > In the interests of full disclosure, I'm the author of EmPy.[color=blue]
            > [/color]
            Cool :)
            [color=blue]
            > All I meant by that note was that EmPy was not primarily designed for
            > blazing speed; that is, it could easily be made much more efficient in a
            > lot of ways. I've never had a need to do so, so it's always been low
            > priority. I've certainly never heard of any complaints of EmPy's speed
            > (or lack therefore) as being a problem in the field. Unless you huge
            > realtime demands, I doubt EmPy's speed would be a major impediment. (Of
            > course, if you find that it is, please tell me!)[/color]

            No huge demands, just simple templating for a database-driven website.
            I'll give EmPy a try, thank you.

            --
            Ksenia

            Comment

            • Ville Vainio

              #7
              Re: templating system

              >>>>> "Erik" == Erik Max Francis <max@alcyone.co m> writes:

              Erik> All I meant by that note was that EmPy was not primarily
              Erik> designed for blazing speed; that is, it could easily be made
              Erik> much more efficient in a lot of ways. I've never had a need

              It would be interesting to see benchmarks comparing different
              templating system. I suppose a web templating system like PSP (of
              mod_python) would be optimized for speed.

              --
              Ville Vainio http://tinyurl.com/2prnb

              Comment

              • David Asorey ?lvarez

                #8
                Re: templating system

                Ksenia Marasanova <ksenia.marasan ova@gmail.com> wrote in message news:<mailman.1 644.1113148510. 1799.python-list@python.org >...[color=blue]
                > Hi,
                >
                > I am looking for fast, simple templating system that will allow me to
                > do the following:
                > - embed Python code (or some templating code) in the template
                > - generate text output (not only XML/HTML)
                >
                > I don't need a framework (already have it), but just simple
                > templating. The syntax I had in mind is something like that:
                > ...[/color]

                Have you tried cherrytemplate? . It is designed for using with
                cherrypy, but it can be easily used alone.

                Find information, resources and relevant links for python-hosting.com. This domain may be for sale.


                --
                David.

                Comment

                Working...