listing25-1.py 482 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python
  2. import cgi
  3. form = cgi.FieldStorage()
  4. text = form.getvalue('text', open('simple_edit.dat').read())
  5. f = open('simple_edit.dat', 'w')
  6. f.write(text)
  7. f.close()
  8. print("""Content-type: text/html
  9. <html>
  10. <head>
  11. <title>A Simple Editor</title>
  12. </head>
  13. <body>
  14. <form action='simple_edit.cgi' method='POST'>
  15. <textarea rows='10' cols='20' name='text'>{}</textarea><br />
  16. <input type='submit' />
  17. </form>
  18. </body>
  19. </html>
  20. """.format(text))