Wystąpił błąd wynikający z BadRequestKeyError z powodu dostępu do klucza, który nie istnieje w request.form .
ipdb> request.form['u_img']
*** BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
Przesłane pliki są umieszczane w request.files a nie request.form słownik. Ponadto musisz zgubić pętlę, ponieważ wartość wpisana w u_img jest instancją FileStorage i nie iterowalny .
@app.route('/', methods=['GET', 'POST'])
def index():
target = os.path.join(app_root, 'static/img/')
if not os.path.isdir(target):
os.makedirs(target)
if request.method == 'POST':
...
file = request.files['u_img']
file_name = file.filename or ''
destination = '/'.join([target, file_name])
file.save(destination)
...
return render_template('index.html')