[Tutor] Really basic web templating

Steve Willoughby steve at alchemy.com
Mon Oct 1 06:41:12 CEST 2007


wormwood_3 wrote:
> Well yes and no:-) This sort of application would fall under the 
> sprawling category of CGI, yes, and I can use Python scripts on my web 
> server, so it is supported. But nearly every tutorial I have seen 
> regarding Python and CGI only have to do with form submissions, doing 
> calculations and other things with data sent from webpages to Python 
> scripts. But that is not really what I want to do. I am wondering what a 
> script would need to do to take requests for pages on my site, and 
> generate them from templates. I am not sure if I can do this without 
> having access to Apache rewrite rules, etc.
> 
> Perhaps this is just another area of CGI that I missed and have not seen 
> tutorials on. If it is and you have seen some, please share!
> 

Yes, it's just another area of CGI that you missed.  Things like wikis 
do this, for one example.  If you request a URL you get a script which 
serves the page if it exists, or creates a blank one if it doesn't.

You can use Python's string template module as an easy way to format up 
variable text into style templates you set up as text files, or use a 
database backend, or whatever.

--steve

> -Sam
> 
> ________________
> ----- Original Message ----
> From: Ian Witham <witham.ian at gmail.com>
> To: wormwood_3 <wormwood_3 at yahoo.com>
> Cc: Python Tutorlist <tutor at python.org>
> Sent: Sunday, September 30, 2007 11:52:38 PM
> Subject: Re: [Tutor] Really basic web templating
> 
> 
> 
> On 10/1/07, *wormwood_3* <wormwood_3 at yahoo.com 
> <mailto:wormwood_3 at yahoo.com>> wrote:
> 
>     Hello all,
> 
>     I am trying to think of a way to make this happen, but it may not be
>     at all possible:-) I would like to use Python to generate pages on
>     demand for my website. By this I mean, when someone hits
>     www.mysite.com/pagex.html <http://www.mysite.com/pagex.html>, I want
>     to generate the page pagex.html via a Python script.
> 
>     I have a script setup that can generate a page from a template file
>     and a file with the body and title of the page in particular I want
>     to generate. Now from this, I need to somehow be able to respond to
>     requests, and then generate the page based on the page requested. I
>     want to do this because my site is on a shared hosting account, so I
>     cannot install a web framework like Django, and the site's pages
>     will be rather simple. At the same time, I would like to use
>     templating, so I do not have repeated identical code between the pages.
> 
>     Any ideas on this?
> 
> 
> It sounds like you want to use CGI. I think virtually all web servers 
> support it and there are a ton of CGI tutorials on the web
> 
> Ian.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list