Python CGI

BJ Swope bigblueswope at gmail.com
Thu Dec 1 06:17:25 EST 2005


Here's a snippet of code I use in a CGI I use...

I check to see if the params has any data, if it does then return that data
and some other data that comes from the params.  If params is empty, then
draw a different page that says give me some data.

    if len(params):
        return params,inc_fields
    else:
        generate_form()
        sys.exit(1)


def generate_form():
    html_stuff.print_headers('Error','FF0000')
    print "Need some information for which to search...\n\n<br><br>\n"
    html_stuff.form_open('search.cgi')
    html_stuff.submit_button('Try Again')
    print '<br><a href="new_contact.cgi">Addd New User</a><br>'
    html_stuff.form_close()
    html_stuff.print_footers()


On 30 Nov 2005 20:52:01 -0800, jbrewer <jeremy.d.brewer at gmail.com> wrote:
>
> I need to update a CGI script I have been working on to perform
> validation of input files.  The basic idea is this:
>
> 1.) HTML page is served
> 2.) User posts file and some other info
> 3.) Check file for necessary data
>     * If data is missing, then post a 2nd page requesting needed data
>     * If data is present, continue to 4
> 4.) Process input file and display results (processing path depends on
> whether data from 3 was present in file or had to be input by user)
>
> I'm unsure of the best way to implement step 3.  Is it even possible to
> put all of this into one script?  Or should I have one script check the
> file for the data, then pass the info on to a 2nd script?  The
> cgi.FieldStorage() function should only be called once, so it seems
> like it's not possible to read a form and then repost another one and
> read it.  If this is true and I need 2 scripts, how do I pass on the
> information in step 3 automatically if the file has the proper data and
> no user input is needed?
>
> Sorry if this is a dumb question (or unclear), but this is my
> (ever-growing) first CGI script.  Thanks.
> Jeremy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



--
"But we also know the dangers of a religion that severs its links with
reason and becomes prey to fundamentalism" --  Cardinal Paul Poupard
"It morphs into the Republican party!"  -- BJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051201/eee712b1/attachment.html>


More information about the Python-list mailing list