Flask在发送文件时返回404

时间:2017-06-16 17:33:05

标签: python flask

路径正确,文件存在。

@app.route('/Users/<username>/<filename>')
def send_image(username, filename):
    return send_from_directory('/Users/'+username, filename)
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /myuploads HTTP/1.1" 200 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/1185392_716316861727493_1066399254_n.jpg HTTP/1.1" 404 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/boy.jpg HTTP/1.1" 404 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/gg.jpeg HTTP/1.1" 404 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/IMG_1409.PNG HTTP/1.1" 404 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/IMG_2743.JPG HTTP/1.1" 404 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/IMG_2757.JPG HTTP/1.1" 404 -
127.0.0.1 - - [16/Jun/2017 20:29:00] "GET /Users/alon123/secondpage.png HTTP/1.1" 404 -

这是目录结构: enter image description here

根是Ludbox,调用上面提到的函数的html可以在模板中找到。

1 个答案:

答案 0 :(得分:0)

尝试向端点添加正斜杠:

@app.route('/Users/<username>/<filename>/')