I am making a simple app where I have to send certain data from one html file to another through flask.
home.html
<a href="ocr">
<button type="submit" class="btn" id="submit">GO!!</button>
</a>
home.js
btn.addEventListener('click', function (e) {
fetch('/ocr', {
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify(s),
});
});
server.py
@app.route("/", methods=["GET", "POST"])
def root():
return render_template("home.html")
@app.route("/ocr", methods=["GET", "POST"])
def ocr():
output = request.get_json()
result = json.loads(output)
#I want to take the result from here to index.html as json
#return render_template("index.html")
If I uncomment the render_template line, flask is throwing the following error.
Bad Request
Did not attempt to load JSON data because the request Content-Type was not 'application/json'.
How do I solve this?
source https://stackoverflow.com/questions/72636890/how-to-send-data-from-js-file-to-another-js-file-through-flask
Comments
Post a Comment