help: Problem with cgi form

Chris Dutton chris at cmb-enterprises.com
Mon Feb 25 14:48:04 EST 2002


In <mailman.1014420097.13372.python-list at python.org> Gustavo Cordova
<gcordova at hebmex.com> wrote:
>> 
>> I'm a beginner. How do I do this? It's probly very simple ......
>> 
>> I have a hidden input on a cgi form... 
>> 
>>     print '<INPUT TYPE=HIDDEN NAME= "last_pos" 
>> VALUE=',last_byte_pos,'>'
>> 
>> I need the VALUE to be the  variable "last_byte_pos", but 
>> unfortunately 
>> when I run the script for the first time the script crashes 
>> because it's 
>> undeclared. 
>> 
>> What subroutine do I use to check if last_byte_pos is undeclared, and >> assign it a default value if it is? 

How about...

import cgi
form = cgi.FieldStorage(keep_blank_values=1)
if form.has_key("last_byte_pos"):
	last_byte_pos = form["last_byte_pos"]
else:	last_byte_pos = default_value



More information about the Python-list mailing list