In mod_python Publisher, I could write a file loader, (uploader.py in this example) using code like this:
def index():
html = '''
<html>
<body>
<form id="fileUpload" action="uploader.py/upload" enctype="multipart/form-data" method="post">
<input type="file" id="file" name="file_name"/>
<input type="submit" value="Upload"/>
</form>
</body>
</html>
'''
return html
def upload(req, file_name):
fd = open("/mydir/myfile", "w")
for line in file_name.file.readlines():
fd.write(line)
fd.close()
This example, excludes any error checking but illustrates what I could do with mod_python and Publisher. The key things are that Publisher was able to call my function, upload, in the file uploader.py and pass it an argument, file_name with the attribute file with the file that was selected in the form.
What I want to do is to do the same thing in mod_wsgi. I'm looking for a way to call a function like this from a form and invoke my function in a similar fashion. I've looked at webob but cannot figure out how to do the same thing with this package. I would appreciate any help in coding a similar solution without having to use mod_python and Publisher.