如何使用Bottle访问上传的文件? [英] How do I access an uploaded file with Bottle?

查看:127
本文介绍了如何使用Bottle访问上传的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传带有瓶子的文本文件,然后阅读。我怎样才能做到这一点?以下是我尝试过但没有起作用的内容。

I'd like to upload a text file with bottle, and then read it. How can I do this? Below is what I've tried and didn't work.

HTML:

<form action="/load_from_file" method="post">
  <div>
    Load File: <input type="file" name="file"/>
    <input type="submit" value="Submit"/>
  </div>
</form>

瓶装路线:

@post('/load_from_file')
def load_from_file():
    list_file = request.forms.get("file")
    print request.files.get("file")
    print request.files["file"]
    return "how do I get the uploaded file?"


推荐答案

您应该添加属性 enctype = multipart / form-data 形成表单标签。

You should add attribute enctype="multipart/form-data" to form tag.

这篇关于如何使用Bottle访问上传的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆