Sending Data to an HTML File : CGI « Network « Python

Home
Python
1.2D
2.Application
3.Buildin Function
4.Class
5.Data Structure
6.Data Type
7.Database
8.Development
9.Dictionary
10.Event
11.Exception
12.File
13.Function
14.GUI Pmw
15.GUI Tk
16.Language Basics
17.List
18.Math
19.Network
20.String
21.System
22.Thread
23.Tuple
24.Utility
25.XML
Python » Network » CGIScreenshots 
Sending Data to an HTML File
 

File:demo.py

#!c:/Python25/python
import cgi

def send_formdic :
    fName = dic.getvalue("firstname""" )
    lName = dic.getvalue("lastname""" )

    flag = intdic.getvalue("flag""0") )

    print "<form action=\"demo.py\">"
    if flag == and fName == "" :
        print "<p><FONT COLOR='red'>Enter your first name:</FONT></p>"
    else :
        print "<p>Enter your first name:</p>"

    if fName != "" :
        print "<input type=\"text\" name=\"firstname\" value=\""+fName+"\" size=\"40\">"
    else :
        print "<input type=\"text\" name=\"firstname\" size=\"40\">"

    if flag == and lName == "" :
        print "<p><FONT COLOR='red'>Enter your last name:</FONT></p>"
    else :
        print "<p>Enter your last name:</p>"
    if lName != "" :
        print "<input type=\"text\" name=\"lastname\" value=\""+lName+"\" size=\"40\">"
    else :
        print "<input type=\"text\" name=\"lastname\" size=\"40\">"
    print "<p>"
    print "<input type=\"submit\">"
    print "<input type=\"reset\">"
    print "<input type=\"hidden\" name=\"flag\" value=\"1\">"
    print "</p>"

def gen_outputdic :

    error = 0

    fName = dic.getvalue("firstname""" )
    lName = dic.getvalue("lastname""" )

    if fName == "" or lName == "" :
        error = 1

    if error == :
        print "Hello there " + fName + " " + lName
    return error

print "Content-Type: text/html\n\n"
print "<HTML>"
form = cgi.FieldStorage()
res = gen_output(form)
if res == 1:
    send_form(form)
print "<form>"
print "</html>"

   
  
Related examples in the same category
1.Get form value
2.Get and set Cookies
3.Uploading Files
4.Redirection
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.