我在本地机器代码中使用Flask上传有问题但是当使用apache将代码上传到服务器时显示错误
IOError:[Errno 2]没有这样的文件或目录: u'app /静态/化身/ KHUON.S.png'
代码:
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
app.config['UPLOAD_FOLDER'] = 'app/static/avatars'
app.config['MAX_CONTENT_LENGTH'] = 1 * 600 * 600
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/User/Profile', methods=['GET', 'POST'])
def upload_profile():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
else:
flash("File extension not allow.")
return redirect(url_for('upload_profile', upload='error'))
return render_template("profile.html")
答案 0 :(得分:1)
好的,在upload.py中,您可以执行类似
的操作List<Meal> MealList = new List<Meal>();
MealList = DataReaderMapToList<Meal>(reader);
os.path.abspath返回给定相对路径的绝对路径。