[mod_python] req.write - display in same page

Graham Dumpleton graham.dumpleton at gmail.com
Thu Apr 19 21:53:31 EDT 2007


On 20/04/07, Prashanth <prashanth.dumpuri at vanderbilt.edu> 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 ?

Only by using JavaScript and AJAX like magic. See:

  http://en.wikipedia.org/wiki/AJAX

That or perhaps resort to using HTML frames in some way.

Graham


More information about the Mod_python mailing list