如何使用web.py上传多个文件?

时间:2014-08-26 07:38:06

标签: python web.py

我试图用web.py获取多个文件。 表格是这样的:

<form method="POST" action="/addProduct" enctype="mutipart/form-data">
    <input type="text" name="name">
    <input type="text" name="address">
    <textarea form="pro-form" name="des"></textarea>
    <input type="file" name="icon">
    <input type="file" id="uploadSc" name="screen">
    <input type="submit" value="submit">
</form>

Python代码如下:

class addProduct(Auth):
    def GET(self):
        return render.addProduct()

    def POST(self):
        i = web.input(icon={}, screen={})
        name, address, des, icon, screen =  i.name, i.address, i.des, i.icon, i.screen
        # print icon.filename
        print icon
        icon_dir = './static/product/icon/'
        # icon_dir = saveFile(icon, icon_dir)
        screen_dir = './static/product/screen/'
        # screen_dir = saveFile(screen, screen_dir)

        db.insert(product, pro_name=name, pro_url=address, pro_screenurl=screen_dir, pro_iconurl=icon_dir, pro_desc=des)
        return icon

服务器只返回图标的文件名,而不是它的值:(

1 个答案:

答案 0 :(得分:0)

我现在知道答案了......
我错误地将multipart/form-data拼写为mutipart/form-data :(