小编Wil*_*awa的帖子

如何使用瓶子框架上传和保存文件

HTML:

<form action="/upload" method="post" enctype="multipart/form-data">
  Category:      <input type="text" name="category" />
  Select a file: <input type="file" name="upload" />
  <input type="submit" value="Start upload" />
</form>
Run Code Online (Sandbox Code Playgroud)

视图:

@route('/upload', method='POST')
def do_login():
    category   = request.forms.get('category')
    upload     = request.files.get('upload')
    name, ext = os.path.splitext(upload.filename)
    if ext not in ('png','jpg','jpeg'):
        return 'File extension not allowed.'

    save_path = get_save_path_for_category(category)
    upload.save(save_path) # appends upload.filename automatically
    return 'OK'
Run Code Online (Sandbox Code Playgroud)

我正在尝试执行此代码,但它无法正常工作.我做错了什么?

python bottle python-2.7

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

bottle ×1

python ×1

python-2.7 ×1