2017-05-25 58 views
0

我跟着這個tutorial,但我無法獲得文件上傳到我想要的目錄。它說它是成功的,但該文件不在它應該是的目錄中。上傳文件在燒瓶不起作用

更新我改變了我的views.py,試圖修復目錄呼叫,但現在我得到這個錯誤:

File "/home/jsnyder10/Documents/45/app/views.py", line 33, in uploader 
f.save(os.path.join(app.config['UPLOAD_FOLDER']),secure_filename(f.filename)) 
IOError: [Errno 21] Is a directory: '/home/jsnyder10/Documents/45/uploads' 

views.py

@app.route('/mobility_import_html') 
@login_required 
def mobility_import_html(): 
    return render_template('mobility_import_html.html') 


@app.route('/uploader', methods = ['GET', 'POST']) 
def uploader(): 
    if request.method == 'POST': 
     f = request.files['file'] 
     #f.save(secure_filename(f.filename)) 
     f.save(os.path.join(app.config['UPLOAD_FOLDER']),secure_filename(f.filename)) 
     print("f.filename", f.filename) 
     return 'success' 

mobility_import_html.html

{% extends "mobility.html" %} 

{% block mobility %} 
     <form action ="{{ url_for('uploader') }}" method = "POST" 
     enctype = "multipart/form-data"> 
     <input type = "file" name = "file" /> 
     <input type = "submit"/> 
     </form> 
{% endblock %} 

init .py

import os 
from flask import Flask 
from flask.json import JSONEncoder 
from flask_sqlalchemy import SQLAlchemy 
from flask_login import LoginManager 
from flask_mail import Mail 
from flask_babel import Babel, lazy_gettext 
from config import basedir, ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, \ 
MAIL_PASSWORD 
from .momentjs import momentjs 

app.config["UPLOAD_FOLDER"] = os.path.join(basedir, 'uploads') 
+0

「它說:」 說什麼?看看[問] – pvg

+0

你應該鏈接到教程,但我沒有看到保存開幕文件。 – gonczor

+0

對不起,我不能正確粘貼鏈接。現已發佈。 –

回答

0

你保存行應該是這樣的:

f.save(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(f.filename))