我想在烧瓶 peewee 中上传一个文件。我有一个代码,但它会生成“IOError: [Errno 2] No such file or directory: '/lookbook/uploads/1375134_766940759988081_2093520123_n.jpg'”错误。形式 :-
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
查看.py:-
from werkzeug import secure_filename
import os
UPLOAD_FOLDER = '/lookbook/uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/up', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
filename = secure_filename(file.filename)
#return filename
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('up',filename=filename))
return 'hello'
else:
return render_template('fileup.html');
请大家帮我解决这个问题。