python - UnboundLocalError: local variable 'filename' referenced before assignment -
i m trying file names , display list, having following error, of unboundlocalerror: local variable 'filename' referenced before assignment
here code, m working on , seems loop not set.
@media.route('/uploadajax', methods=['post']) def upldfile(): if request.method == 'post': files = request.files.getlist('file[]') f in files: if f , allowed_file(f.filename): filename = secure_filename(f.filename) updir = os.path.join(basedir, 'upload/') f.save(os.path.join(updir, filename)) file_size = os.path.getsize(os.path.join(updir, filename)) else: app.logger.info('ext name error') return jsonify(error='ext name error') return jsonify(name=filename, size=file_size)
how fix loop issue?
adding lines below before for
loop fix problem:
files = request.files.getlist('file[]') if not files: return jsonify(error='please add files') f in files: # loop body
Comments
Post a Comment