Bottle request.files.getall() returns 空列表

Bottle request.files.getall() returns empty list

我在使用 Bottle 批量上传图片时遇到问题。 request.files.getall() returns 空列表,即使我正在选择和上传文件。

我的表单如下所示:

<form action="/upload" method="POST">
    <div class="form-group">
        <label for="gallery">Select images:</label>
        <input id="gallery" type="file" name="gallery" accept=".gif,.jpg,.jpeg,.png" multiple>
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
</form>

我的控制器看起来像这样:

@route('/upload', method='POST')
def newGallery():
    name = request.forms.get('name')
    pictures = request.files.getall('gallery')

    for picture in pictures:
        print(picture.filename)

    return template('new.html')

感谢您的帮助。

forms.getall(*) 工作

*.py文件

@bottle.get('/go')
def go():
    return bottle.template('new.html')

@bottle.post('/go')
def goo():
    name = bottle.request.forms.get('email')
    pictures = bottle.request.forms.getall('gallery')
    for picture in pictures:
        print(picture)
    return bottle.template(' hi {{name}}, {{picture}} ', name=name, picture=picture)

此外,将 new.html 中的 form 标记更改为

    <form method="post">