2017-10-14 77 views
-1

我想上傳文件到服務器使用燒瓶,但文件*不上傳。文件沒有上傳在燒瓶

我是新來的python和燒瓶。

import os 
from flask import * 

app = Flask(__name__) 

APP_ROOT = os.path.dirname(os.path.abspath(__file__)) 

@app.route('/') 
def index(): 
    return render_template('upload.html') 

@app.route('/upload', methods = ['POST']) 
def upload(): 
    target = os.path.join(APP_ROOT, 'uploads/') 

    if not os.path.join(target): 
     os.mkdir(target) 

    for file in request.files.getlist('file'): 
     print(file.filename) 
     destination = '/'.join([target, file.filename]) 
     print(destination) 
     file.save(destination) 

    return render_template('successful.html') 

if __name__ == '__main__': 
    app.run(debug = True) 

upload.html

<!DOCTYPE html> 
<html> 
<head> 
    <title> Upload file </title> 
</head> 
<body> 
    <form id="upload-form" action="{{ url_for('upload') }}" 
    method="post" enctype="multipart/form-data"> 
     <input type="file" name="cssv_file" multiple> 
     <input type="submit" value="Submit"/> 
    </form> 
</body> 
</html> 
+0

您指定的領域'cssv_file',不'file':'請求。 files.getlist('cssv_file')' – davidism

+0

點擊後拋出'FileNotFoundError' ing提交@davidism – Sanjay

+0

你按照我以前的評論? – davidism

回答

0

改變這一行

if not os.path.join(target): 

if not os.path.isdir(target):