473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 ---
Sep 1 '05 #1
8 1423
John M. Gabriele wrote:
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?


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
Sep 1 '05 #2
On Thu, 01 Sep 2005 03:10:07 -0400, "John M. Gabriele"
<jo************@yahooz.com> wrote:
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?

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

Thanks,
---John

Sep 1 '05 #3
John M. Gabriele wrote:
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?


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
Sep 1 '05 #4
On Thu, 01 Sep 2005 09:20:51 +0200, Diez B. Roggisch wrote:
John M. Gabriele wrote:
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?


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

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:
http://www.onlamp.com/pub/a/python/2...ver_pages.html

--
--- if contacting via email, remove zees ---
Sep 1 '05 #5
On Thu, 01 Sep 2005 13:12:14 +0100, Fuzzyman wrote:
On Thu, 01 Sep 2005 03:10:07 -0400, "John M. Gabriele"
<jo************@yahooz.com> wrote:
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?

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``.

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.


I'm pretty sure their is an entry on the Python.org WIKI about
templating.
Whoops. I ended up hitting this page first:
http://wiki.python.org/moin/CgiScripts
and now I'm sticking with it. :)

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

---John


All the best,

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

Thanks,
---John


--
--- if contacting via email, remove zees ---
Sep 2 '05 #6
On Thu, 01 Sep 2005 19:10:14 +0200, Walter Dörwald wrote:
John M. Gabriele wrote:
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?


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


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 ---
Sep 2 '05 #7
John M. Gabriele wrote:
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?

There are a million ways to solve this particular problem, despite
Python's "TSBOAPOOOWTDI" (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("siteroot/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/

Sep 2 '05 #8
On Thu, 01 Sep 2005 20:57:56 -0500, Steve Holden wrote:
John M. Gabriele wrote:
[snip]

Is that how it's usually done? If not, what *is* the
usual way of handling this?
There are a million ways to solve this particular problem, despite
Python's "TSBOAPOOOWTDI" (see "import this") philosophy (because the
philosophy is addressing primitive programming rather than application
frameworks).


Yes. :)
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
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.

[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


Thanks Steve!

---John

--
--- if contacting via email, remove zees ---
Sep 2 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jo Voordeckers | last post by:
Hello all, I'm pretty new to the Java newsgroups so I apologize for dropping this into several maybe offtopic groups. I'm sorry! So on to my problem... I've come to a point in our RMI...
0
by: Oleg Paraschenko | last post by:
Hello, I'd like to introduce an article which might be of some interest: Reusing XML Processing Code in non-XML Applications HTML: http://uucode.com/texts/genxml/genxml.html PDF: ...
1
by: richardlane | last post by:
Hi, basic question here - I'm struggling with the transfer from asp to asp.net a bit, especially in seeing the 'bigger picture' of how things are best structured. I have a website made up...
4
by: cjm | last post by:
I have two problems that I suspect will be bread-and-butter problems for the more experienced guys on here, but I'm not the greatest with js. NB: Code snippets at the bottom The first problem...
2
by: Alex Maghen | last post by:
I have a site where most of the pages will have a common "shell" or layout. There will be an outer table which will hold HTML elements but which will *also* hold UserControls (Global Nav, etc.)....
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
2
by: brazil.mg.marcus.vinicius.lima | last post by:
Hi, I'm constructing a query that will performs a lot o datetime calculumns to generate columns. All that operations are dependent of a base calculum that is performed on the query and its...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
8
by: stoogots2 | last post by:
I would like to reuse the code for gridview sorting for each of the several GridViews that I have on one page. I've not done this before, so I am seeking a more elegant and reusable solution than...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.