[COLUG] CGI Question

Tom Hanlon tom at functionalmedia.com
Tue Aug 7 07:12:56 EDT 2007


On 6 Aug 2007, at 18:31, Mark Erbaugh wrote:

> I hope I'm missing something simple.
>
> I'm starting to do some CGI work in Python. Right now, I'm doing the
> code directly in Python. I'm hoping to avoid some of the larger
> frameworks (i.e. Zope, et al).
>
> Using python's cgi module, I can successfully extract data entered on
> the form by the user after a POST or GET.  I can use this data and  
> build
> a new web page with the response.
>

You seem to be able to do what is required..

Have the form action be the page itself.
Then in the form input fields you need a value=""

Your python will be something like value=" PYTHON IF form submitted  
put value here if not leave blank"

Do not expect html coding to be elegant. By its very stateless nature  
it is ugly. So you will have to add some python to the page that was  
generated by your html editor. I would not be surprised if your html  
editor makes things nastier than they have to be.

You may want to look into some templating engine, I do not know what  
python has.

Once you see that you are delivering nasty html pages you may want to  
look  into an embedded option. PHP is embedded by default but there  
is emb_perl is there emb_python ?

If not then print >>>>
or whatever syntax python has to print large blocks of text , becomes  
your friend.

--
Tom


> What I want to do now is give the user an opportunity to edit their
> input data. To do this, I want to redisplay the input page, but  
> with the
> values entered by the user.  So far, the only solution I've come up  
> with
> (but haven't implemented) involves reconstructing the entire input web
> page. The web page was created in an HTML editor and that looks like
> it's pretty complex, especially with things like selection lists,  
> since
> the options are in different tags.
>
> 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.
>
>
> TIA,
> Mark
>
> _______________________________________________
> colug432 mailing list colug432 at colug.net
> http://www.colug.net/mailman/listinfo/colug432



More information about the colug432 mailing list