Closed Asa-Nisi-Masa closed 3 years ago
Dropzone.js will upload file in asynchronous AJAX request, it will not update the page with your response. If you just want to send a success message, you can return the message directly:
from flask import jsonify
@app.route('/', methods=['POST', 'GET'])
def upload():
message = None
print(request.method, request.files)
if request.method == "POST":
# do something with the file ...
message = "done processing file"
return jsonify(message=message) # <--
return render_template('index.html')
then listen to success
event on client-side to receive the response (and do something with it):
{{ dropzone.config(custom_options="success: function(file, response){ alert(response.message); }") }}
Hello. I'm unable to pass a variable to a template after a file upload. The code is modified basic example:
index.html
and the Python side
app.py
But no 'message' is rendered. Basically the problem is that the only time the backend sees the uploaded file is when the request method is
POST
, but then for some reason themessage=message
argument does not work - nothing changes on the webpage. The only way to pass a variable to a template is when the request method isGET
but then the backend does not see the uploaded file... Any ideas how to solve this?