python - send_from_directory with dynamic path -


i'm trying use send_from_directory return file.this code works fine.

@app.route("/img/<filename>") @login_required def send_img(filename):     path = '../py/img_detected/invador'     return send_from_directory(path,filename) 

but if change path dynamic path like

@app.route("/img/<dir><filename>") @login_required def send_img(dir,filename):     path = '../py/img_detected/%s'%dir     return send_from_directory(path,filename) 

it cannot work. furthermore, tried change path = '../py/img_detected/invador'

dir='invador' path = '../py/img_detected/%s'%dir 

it cannot work either. can tell me reason of problem? , can if want function more flexible?

the error message :

127.0.0.1 - - [07/apr/2017 04:56:41] "get /invador_img http/1.1" 200 - 127.0.0.1 - - [07/apr/2017 04:56:41] "get /img/invador2017-04-07-01-37.png http/1.1" 404 - 

sorry mistake, check code again , find miss '/' in /<dir><filename> should /<dir>/<filename> . , edit path, code should os.path.join(dir, filename) .


Comments