cgi, reusing html. common problem?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John M. Gabriele

    #1

    cgi, reusing html. common problem?

    I'm putting together a small site using Python and cgi.

    (I'm pretty new to this, but I've worked a little with
    JSP/servlets/Java before.)

    Almost all pages on the site will share some common (and
    static) html, however, they'll also have dynamic aspects.
    I'm guessing that the common way to build sites like this
    is to have every page (which contains active content) be
    generated by a cgi script, but also have some text files
    hanging around containing incomplete html fragments which
    you read and paste-in as-needed (I'm thinking:
    header.html.txt , footer.html.txt , and so on).

    Is that how it's usually done? If not, what *is* the
    usual way of handling this?

    Thanks,
    ---John

    --
    --- if contacting via email, remove zees ---


  • Diez B. Roggisch

    #2
    Re: cgi, reusing html. common problem?

    John M. Gabriele wrote:[color=blue]
    > I'm putting together a small site using Python and cgi.
    >
    > (I'm pretty new to this, but I've worked a little with
    > JSP/servlets/Java before.)
    >
    > Almost all pages on the site will share some common (and
    > static) html, however, they'll also have dynamic aspects.
    > I'm guessing that the common way to build sites like this
    > is to have every page (which contains active content) be
    > generated by a cgi script, but also have some text files
    > hanging around containing incomplete html fragments which
    > you read and paste-in as-needed (I'm thinking:
    > header.html.txt , footer.html.txt , and so on).
    >
    > Is that how it's usually done? If not, what *is* the
    > usual way of handling this?[/color]

    The basic idea is correct - but there are sooo many other people that
    had the same problem, and thus they creted web-framworks like e.g.
    CherryPy or Django or... and then there is ZOPE. Search this group for
    webframeworks, and you might get more answers than you wanted :)

    Diez

    Comment

    • Fuzzyman

      #3
      Re: cgi, reusing html. common problem?

      On Thu, 01 Sep 2005 03:10:07 -0400, "John M. Gabriele"
      <john_sips_teaz @yahooz.com> wrote:
      [color=blue]
      >I'm putting together a small site using Python and cgi.
      >
      >(I'm pretty new to this, but I've worked a little with
      >JSP/servlets/Java before.)
      >
      >Almost all pages on the site will share some common (and
      >static) html, however, they'll also have dynamic aspects.
      >I'm guessing that the common way to build sites like this
      >is to have every page (which contains active content) be
      >generated by a cgi script, but also have some text files
      >hanging around containing incomplete html fragments which
      >you read and paste-in as-needed (I'm thinking:
      >header.html.tx t, footer.html.txt , and so on).
      >
      >Is that how it's usually done? If not, what *is* the
      >usual way of handling this?
      >[/color]

      Having a template and inserting dynamic values into it is very common.

      You'll have more luck looking for 'python templating systems'.

      I use a module called 'embedded code' - which is part of firedrop by
      Hans Nowak. See http://www.voidspace.org.uk/python/firedrop2/

      Popular templating engines include Cheetah and TAL.

      You can also roll your own basic one using the string method
      ``replace``.

      I'm pretty sure their is an entry on the Python.org WIKI about
      templating.

      All the best,

      Fuzzy
      http://www.voidspace.org.uk/python

      [color=blue]
      >Thanks,
      >---John[/color]

      Comment

      • Walter Dörwald

        #4
        Re: cgi, reusing html. common problem?

        John M. Gabriele wrote:
        [color=blue]
        > I'm putting together a small site using Python and cgi.
        >
        > (I'm pretty new to this, but I've worked a little with
        > JSP/servlets/Java before.)
        >
        > Almost all pages on the site will share some common (and
        > static) html, however, they'll also have dynamic aspects.
        > I'm guessing that the common way to build sites like this
        > is to have every page (which contains active content) be
        > generated by a cgi script, but also have some text files
        > hanging around containing incomplete html fragments which
        > you read and paste-in as-needed (I'm thinking:
        > header.html.txt , footer.html.txt , and so on).
        >
        > Is that how it's usually done? If not, what *is* the
        > usual way of handling this?[/color]

        I don't know if it's the *usual* way, but you could give XIST a try
        (http://www.livinglogic.de/Python/xist). It was developed for exactly
        this purpose: You implement reusable HTML fragments in Python and you
        can use any kind of embedded dynamic language (PHP and JSP are supported
        out of the box).

        Bye,
        Walter Dörwald

        Comment

        • John M. Gabriele

          #5
          Re: cgi, reusing html. common problem?

          On Thu, 01 Sep 2005 09:20:51 +0200, Diez B. Roggisch wrote:
          [color=blue]
          > John M. Gabriele wrote:[color=green]
          >> I'm putting together a small site using Python and cgi.
          >>
          >> (I'm pretty new to this, but I've worked a little with
          >> JSP/servlets/Java before.)
          >>
          >> Almost all pages on the site will share some common (and
          >> static) html, however, they'll also have dynamic aspects.
          >> I'm guessing that the common way to build sites like this
          >> is to have every page (which contains active content) be
          >> generated by a cgi script, but also have some text files
          >> hanging around containing incomplete html fragments which
          >> you read and paste-in as-needed (I'm thinking:
          >> header.html.txt , footer.html.txt , and so on).
          >>
          >> Is that how it's usually done? If not, what *is* the
          >> usual way of handling this?[/color]
          >
          > The basic idea is correct - but there are sooo many other people that
          > had the same problem, and thus they creted web-framworks like e.g.
          > CherryPy or Django or... and then there is ZOPE. Search this group for
          > webframeworks, and you might get more answers than you wanted :)
          >
          > Diez[/color]


          Thanks Diez. Glad to hear I'm on the right track. :)

          From poking around, it looks to me like these Python web
          frameworks are to Python as JSP is to Java.

          I really don't want to use a "templating language" (a la
          JSP) -- I was hoping to just stick with straight Python
          and then also html + css. Though I've heard good things
          about CherryPy.

          Looks like mod_python also comes with it's own solution too:
          Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology




          --
          --- if contacting via email, remove zees ---


          Comment

          • John M. Gabriele

            #6
            Re: cgi, reusing html. common problem?

            On Thu, 01 Sep 2005 13:12:14 +0100, Fuzzyman wrote:
            [color=blue]
            > On Thu, 01 Sep 2005 03:10:07 -0400, "John M. Gabriele"
            > <john_sips_teaz @yahooz.com> wrote:
            >[color=green]
            >>I'm putting together a small site using Python and cgi.
            >>
            >>(I'm pretty new to this, but I've worked a little with
            >>JSP/servlets/Java before.)
            >>
            >>Almost all pages on the site will share some common (and
            >>static) html, however, they'll also have dynamic aspects.
            >>I'm guessing that the common way to build sites like this
            >>is to have every page (which contains active content) be
            >>generated by a cgi script, but also have some text files
            >>hanging around containing incomplete html fragments which
            >>you read and paste-in as-needed (I'm thinking:
            >>header.html.t xt, footer.html.txt , and so on).
            >>
            >>Is that how it's usually done? If not, what *is* the
            >>usual way of handling this?
            >>[/color]
            >
            > Having a template and inserting dynamic values into it is very common.
            >
            > You'll have more luck looking for 'python templating systems'.
            >
            > I use a module called 'embedded code' - which is part of firedrop by
            > Hans Nowak. See http://www.voidspace.org.uk/python/firedrop2/
            >
            > Popular templating engines include Cheetah and TAL.
            >
            > You can also roll your own basic one using the string method
            > ``replace``.[/color]


            Thanks for the reply Fuzzy.

            I'm going to try rolling my own. I found this *great* article:
            http://www.devshed.com/index2.php?op...ge=0&hide_js=1

            and it shows pretty much exactly what I think I want: separate
            html files containing fragments of a complete page, then some
            python code to read in the html fragment, and replace your
            generated code with some placeholder.

            [color=blue]
            >
            > I'm pretty sure their is an entry on the Python.org WIKI about
            > templating.[/color]

            Whoops. I ended up hitting this page first:

            and now I'm sticking with it. :)

            I like CGI. I want to keep things as simple as possible. :)

            ---John

            [color=blue]
            >
            > All the best,
            >
            > Fuzzy
            > http://www.voidspace.org.uk/python
            >
            >[color=green]
            >>Thanks,
            >>---John[/color][/color]

            --
            --- if contacting via email, remove zees ---


            Comment

            • John M. Gabriele

              #7
              Re: cgi, reusing html. common problem?

              On Thu, 01 Sep 2005 19:10:14 +0200, Walter Dörwald wrote:
              [color=blue]
              > John M. Gabriele wrote:
              >[color=green]
              >> I'm putting together a small site using Python and cgi.
              >>
              >> (I'm pretty new to this, but I've worked a little with
              >> JSP/servlets/Java before.)
              >>
              >> Almost all pages on the site will share some common (and
              >> static) html, however, they'll also have dynamic aspects.
              >> I'm guessing that the common way to build sites like this
              >> is to have every page (which contains active content) be
              >> generated by a cgi script, but also have some text files
              >> hanging around containing incomplete html fragments which
              >> you read and paste-in as-needed (I'm thinking:
              >> header.html.txt , footer.html.txt , and so on).
              >>
              >> Is that how it's usually done? If not, what *is* the
              >> usual way of handling this?[/color]
              >
              > I don't know if it's the *usual* way, but you could give XIST a try
              > (http://www.livinglogic.de/Python/xist). It was developed for exactly
              > this purpose: You implement reusable HTML fragments in Python and you
              > can use any kind of embedded dynamic language (PHP and JSP are supported
              > out of the box).
              >
              > Bye,
              > Walter Dörwald[/color]

              Thanks Walt. :) Though, it seems simpler to me to just stick with some
              plain vanilla static html, and pull that in to my cgi scripts as
              necessary.

              ---John

              --
              --- if contacting via email, remove zees ---


              Comment

              • Steve Holden

                #8
                Re: cgi, reusing html. common problem?

                John M. Gabriele wrote:[color=blue]
                > I'm putting together a small site using Python and cgi.
                >
                > (I'm pretty new to this, but I've worked a little with
                > JSP/servlets/Java before.)
                >
                > Almost all pages on the site will share some common (and
                > static) html, however, they'll also have dynamic aspects.
                > I'm guessing that the common way to build sites like this
                > is to have every page (which contains active content) be
                > generated by a cgi script, but also have some text files
                > hanging around containing incomplete html fragments which
                > you read and paste-in as-needed (I'm thinking:
                > header.html.txt , footer.html.txt , and so on).
                >
                > Is that how it's usually done? If not, what *is* the
                > usual way of handling this?
                >[/color]
                There are a million ways to solve this particular problem, despite
                Python's "TSBOAPOOOW TDI" (see "import this") philosophy (because the
                philosophy is addressing primitive programming rather than application
                frameworks).

                You could do something as simple as writing a module "webPage" that
                defines a function page(path, content) that does something along the
                lines of:

                def page(path, content):
                return """\
                <html>
                <title>If you want titles, add another argument</title>
                </head>
                <body>
                <this would be code to build a nav bar, omitting a hypertext link for
                the path given as an argument - I'm just ignoring it in this example>
                %s
                </body>
                </html>
                """ % content

                Then in your generation routines you can build up content in the
                traditional way by generating individual fragments of HTML and appending
                them to a list. So you start with

                content = []

                then for every fragment you generate you do

                content.append( fragment)

                and finally your content is generated with something like

                content = webPage.page("s iteroot/subdir/page1.html", "".join(content ))

                If you don't care that a page contains a navbar link to itself (a sign
                of web immaturity, but by no means inexcusable) then you don't even need
                to pass the page's path into the function.

                Hope this gives you a few ideas. This problem has been considered by
                many people, but clearly no outstanding solution has yet been devised,
                otherwise we'd all be using it.

                regards
                Steve
                --
                Steve Holden +44 150 684 7255 +1 800 494 3119
                Holden Web LLC http://www.holdenweb.com/

                Comment

                • John M. Gabriele

                  #9
                  Re: cgi, reusing html. common problem?

                  On Thu, 01 Sep 2005 20:57:56 -0500, Steve Holden wrote:
                  [color=blue]
                  > John M. Gabriele wrote:[color=green]
                  >> [snip]
                  >>
                  >> Is that how it's usually done? If not, what *is* the
                  >> usual way of handling this?
                  >>[/color]
                  > There are a million ways to solve this particular problem, despite
                  > Python's "TSBOAPOOOW TDI" (see "import this") philosophy (because the
                  > philosophy is addressing primitive programming rather than application
                  > frameworks).[/color]

                  Yes. :)
                  [color=blue]
                  > You could do something as simple as writing a module "webPage" that
                  > defines a function page(path, content) that does something along the
                  > lines of:
                  >
                  > def page(path, content):
                  > return """\
                  > <html>
                  > <title>If you want titles, add another argument</title>
                  > </head>
                  > <body>
                  > <this would be code to build a nav bar, omitting a hypertext link for
                  > the path given as an argument - I'm just ignoring it in this example>
                  > %s
                  > </body>
                  > </html>
                  > """ % content[/color]

                  Ah yes, I see. If the content is completely static, you
                  can use a text file (html fragment) and just read it and
                  paste it in, but for fragments that are *mostly* static,
                  I really like that idea to use a module as you suggest.

                  [color=blue]
                  > [snip]
                  >
                  > Hope this gives you a few ideas. This problem has been considered by
                  > many people, but clearly no outstanding solution has yet been devised,
                  > otherwise we'd all be using it.
                  >
                  > regards
                  > Steve[/color]

                  Thanks Steve!

                  ---John

                  --
                  --- if contacting via email, remove zees ---


                  Comment

                  Working...