[mod_python] req.write - display in same page

Mike Looijmans nlv11281 at natlab.research.philips.com
Fri Apr 20 06:48:29 EDT 2007

In any web application, the solution is to display the same page again 
with the error message added. To the end-user, that has the effect of 
displaying it on the page (which you probably want because the user is 
likely to want to correct the mistake and try again). On success, you 
can redirect to another page to continue the process.

Mike Looijmans
Philips Natlab / Topic Automation

Prashanth wrote:
> Graham and Roberto,
> Apologies for not being clear in my earlier post.
> The following is a part of my HTML code (called index.html) that accepts 
> a file from users, reads and then processes it
> <form action="python/cgi-bin/getFile" method="post" 
> enctype="multipart/form-data">
> <input type="file" name="file" />
> <input type="submit" name="submit" value="Submit" />
> </form>
> Here's my python script (readFile.py) that handles reading the file 
> (that is uploaded by the user)
> from mod_python import apache
> from mod_python.util import FieldStorage
> def handler(req):
> req.content_type = "text/plain"
> form = FieldStorage(req)
> for field in form.list:
> fname = field.filename
> ext = fname.split(".")
> # desired file extension for me is .nml
> if (ext != ".nml):
> req.write("Please input a file with .nml extension")
> else:
> req.write("File has the desired extension..proceeding to process it")
> The way it stands req.write is printing the messages in a reloaded 
> window/ fresh page. Is there a way to print messages from req.write in 
> the same page ? In other words, req.write is writing its messages to 
> http://localhost/index.html/readFile.py. Can I force req.write to write 
> the messages to http://localhost/index.html ?
> Thanks
> Prashanth

More information about the Mod_python mailing list