[COLUG] CGI Question
Aaron Howard
archanoid at gmail.com
Tue Aug 7 10:34:19 EDT 2007
On Monday 06 August 2007 6:31:08 pm Mark Erbaugh wrote:
> Is there a reverse process to extracting form data where data can be
> applied to a web page? What I'm looking for is a way to fill in a data
> structure similar to the cgi.FieldStorage() object and then be able to
> combine that with an HTML page and have the value put into the
> appropriate input fields.
>
You will want to do one of two things:
1. use a templating toolkit that works with Python
2. half-ass^Wimplemen your own
Personally, I tend to use the re module to do my own.
What you do is you create a config file (config.py, for instance)
in which you declare a class with basically a bunch of configuration
parameters such as the names and locations of template files...then, in your
main python cgi app, you
from config.py import ConfigClass
cfg = ConfigClass
theform = cfg.theFormTemplateFile
then you
import re
and use regular expression substitution to find fields in your template file
and replace them with your data. I use things like
<input name="foo" value="<!--REPLACEMEWITHFOOVALUE-->" type="text">
Anyway, feel free to e-mail me off-list and we can go a little further with
this convo and I can give you more code examples.
-Aaron
More information about the colug432
mailing list