Re: [Tutor] Really basic web templating
Check to see if mod_python is installed/installable. It would quite easily give you a very simple interface to do what you're looking for. --Michael -- Michael Langford Phone: 404-386-0495 Consulting: http://www.TierOneDesign.com/ On 9/30/07, wormwood_3 <[EMAIL PROTECTED]> 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, 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? > > Thanks, > Sam > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
There was another host that I wanted to mention along these lines (for Python sites) that I think is even better: VPSLink (http://www.vpslink.com). They allow root SSH access, and can install your choice of OS (lots of linux flavors, ubuntu, SUSE, CentOS, etc) from a control panel. Aside from that they are similar to WebFaction, but having that much flexibility, with the base plan only ~$8/month, is pretty awesome. -Sam - Original Message From: Kent Johnson <[EMAIL PROTECTED]> To: wormwood_3 <[EMAIL PROTECTED]> Cc: Python Tutorlist Sent: Monday, October 1, 2007 8:36:03 AM Subject: Re: [Tutor] Really basic web templating wormwood_3 wrote: > My host actually does support Python. But I don't have access to > Apache rules nor the level of access to install apps like Django, so > I am limited to just scripts I write. Webfaction gives you both - you can install anything you like as long as it doesn't require superuser privileges and you have your own Apache instance that you can tweak any way you like. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
wormwood_3 wrote: > My host actually does support Python. But I don't have access to > Apache rules nor the level of access to install apps like Django, so > I am limited to just scripts I write. Webfaction gives you both - you can install anything you like as long as it doesn't require superuser privileges and you have your own Apache instance that you can tweak any way you like. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
My host actually does support Python. But I don't have access to Apache rules nor the level of access to install apps like Django, so I am limited to just scripts I write. But for that price, i will definitely check out WebFaction! -Sam - Original Message From: Kent Johnson <[EMAIL PROTECTED]> To: wormwood_3 <[EMAIL PROTECTED]> Cc: Python Tutorlist Sent: Monday, October 1, 2007 6:44:45 AM Subject: Re: [Tutor] Really basic web templating wormwood_3 wrote: > I want > to do this because my site is on a shared hosting account, so I cannot > install a web framework like Django Another option is to switch to a hosting account that supports Python. I have been working with WebFaction and I'm very happy with them; an account with Django support is available for less than $10/month. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
wormwood_3 wrote: > I want > to do this because my site is on a shared hosting account, so I cannot > install a web framework like Django Another option is to switch to a hosting account that supports Python. I have been working with WebFaction and I'm very happy with them; an account with Django support is available for less than $10/month. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
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. I am going to assume from your description that you are looking for a way to use a *single* cgi script to handle all page requests to your site, and respond with the appropriate template based on the requested url. If I have assumed incorrectly then you can safely ignore the rest of this message. :) Some mod_rewrite directives are available to .htaccess, IIRC -- so that may be a valid option, only if your webhost has enabled mod_rewrite of course, and they allow overrides with htaccess. Otherwise, this is a fairly simple task if you are content with "ugly" urls. For example, given a url something like http://mysite.com/mycgi.py?page=index.html, a very basic cgi implementation might look like this: #!/usr/bin/env python import cgi form = cgi.FieldStorage() print "Content-type: text/html\n" try: page = form["page"] except KeyError: print file('custom404error.html').read() else: content = file(page.value).read() # ... do something with content ... print content --- If your webhost has enabled mod_actions (I suppose this is unlikely), you can also do the following in .htaccess (again, only if they allow override): AddHandler my-python-handler .html Action my-python-handler /cgi-bin/handler.py which should force apache to set an environment variable named 'PATH_TRANSLATED' with the value of the requested url, and call 'handler.py' for any requested file with an .html extension (that exists) in that directory -- honestly, I've never attempted this myself -- and there is probably a better way, but it's all I can think of ATM. If the file doesn't exist apache returns a 404, which is only desirable if you plan to store your templates on the filesystem. And you can use the os module to access the cgi environment variables: #!/usr/bin/env python import os print "Content-type: text/plain\n" try: path = os.environ["PATH_TRANSLATED"] except: path = 'PATH_TRANSLATED is not defined.' print "The requested url is:", path --- Perhaps you could convince your webhost to install mod_python, if they haven't already. It's fairly trivial to write a simple mod_python handler to accomplish exactly what you are trying to do. HTH, Marty ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
"wormwood_3" <[EMAIL PROTECTED]> wrote > ...nearly every tutorial I have seen regarding Python and CGI only > have to do with form submissions, Thats the most common use of CGI but really a form submission is just a standard HTTP GET/POST request with some predefined variables. In reality the user requests your python script and whatever the script sends to stdout goes to the browser So all you have to do is read in your header, body and footer and stitch them together then send them to stdout. If you want richer functionality you can use templating engines from the frameworks without the framework being present. For example the kid system used in TurboGears can be used standalone to give sophistoicated templating without anything special being done to the web server. Indeed it can even be used outside a web server context. But from your description simple CGI and Python may be all you need. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
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 <[EMAIL PROTECTED]> > To: wormwood_3 <[EMAIL PROTECTED]> > Cc: Python Tutorlist > Sent: Sunday, September 30, 2007 11:52:38 PM > Subject: Re: [Tutor] Really basic web templating > > > > On 10/1/07, *wormwood_3* <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> 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@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
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! -Sam - Original Message From: Ian Witham <[EMAIL PROTECTED]> To: wormwood_3 <[EMAIL PROTECTED]> Cc: Python Tutorlist Sent: Sunday, September 30, 2007 11:52:38 PM Subject: Re: [Tutor] Really basic web templating On 10/1/07, wormwood_3 <[EMAIL PROTECTED]> 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, 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@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Really basic web templating
On 10/1/07, wormwood_3 <[EMAIL PROTECTED]> 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, 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@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Really basic web templating
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, 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? Thanks, Sam ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor