2017-10-14 11 views
-1

J'essaye de télécharger des fichiers dans le serveur en utilisant flask mais les fichiers ne sont pas téléchargés.Fichiers ne téléchargeant pas dans le flacon

Je suis nouveau sur python et flask.

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

Vous nommez le champ 'cssv_file', pas' file': 'demande. files.getlist ('cssv_file') ' – davidism

+0

Il lance' FileNotFoundError' après un clic Envoyer @davidism – Sanjay

+0

avez-vous suivi mon commentaire précédent? – davidism

Répondre

0

Modifier cette ligne

if not os.path.join(target): 

à

if not os.path.isdir(target):