How to upload a file using mod_python?

I want to create a simple form for uploading files, and I must be completely incapable. I read documents and textbooks, but for some reason I do not receive the form data provided. I wrote the smallest amount of code I could test, and it still doesn't work. Any ideas what's wrong?

def index():
    html = '''
    <html>
      <body>
      <form id="fileUpload" action="./result" method="post">
        <input type="file" id="file"/>
        <input type="submit" value="Upload"/>
      </form>
      </body>
    </html>
    '''
    return html

def result(req):
    try: tmpfile = req.form['file']
    except:
        return "no file!"
+3
source share
1 answer

try putting enctype = "multipart / form-data" in your form tag. Your error is not related to mod_python.

+1
source

Source: https://habr.com/ru/post/1704685/


All Articles