From 58d94b716f333e70f53ee29f02f8c153610d2adc Mon Sep 17 00:00:00 2001 From: AIIrondev Date: Mon, 3 Aug 2026 18:34:27 +0200 Subject: [PATCH] fix of the json upload format --- Web/app.py | 5 +++++ Web/templates/upload_batch.html | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Web/app.py b/Web/app.py index 892da71..0533f96 100755 --- a/Web/app.py +++ b/Web/app.py @@ -11860,7 +11860,12 @@ def batch_upload_page(): return render_template('upload_batch.html') +from flask_wtf.csrf import CSRFProtect +csrf = CSRFProtect(app) + + @app.route('/upload_csv_batch', methods=['POST']) +@csrf.exempt def upload_csv_batch(): """ Route for batch adding new items to the inventory via CSV. diff --git a/Web/templates/upload_batch.html b/Web/templates/upload_batch.html index 4db8874..d5108fc 100644 --- a/Web/templates/upload_batch.html +++ b/Web/templates/upload_batch.html @@ -165,14 +165,17 @@ const formData = new FormData(form); - const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); - const fetchOptions = { method: 'POST', body: formData, - credentials: 'include' + credentials: 'include', + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } }; + const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); + if (csrfToken) { fetchOptions.headers = { 'X-CSRFToken': csrfToken