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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -