I am trying to perform two different functions with single submit button, the below script shows the example of what I am trying to get. Thank you for helping me.
Expected solution --> when I click on submit button file has to upload along with map2 has redirect to mapRedirect url.
from flask import flask, render_template, flash, request, redirect,url_for
@app.route('/map2')
def map_2():
return render_template('map2.html')
@app.route('/mapRedirect', methods = ['POST', 'GET'])
def onMap():
if request.method == 'POST':
name = request.form['nm']
return redirect(f"map2")
@app.route('/proc')
def upload_file():
## file upload script
return render_template('proc.html')
map2.html
<iframe name = "Ifrmp", id='mp', src="map2" >
proc.html
<form method="post" enctype="multipart/form-data" target="Ifrmp">
<input type="submit" id='btn' name="nm" value="submit>
You can use JQuery to perform AJAX requests on those two functions.
<input type="submit" id='btn' form value="Click" onclick = 'button1();button2()'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
function button1() {
$.get("/button1");
}
function button2() {
$.post("/button2");
}
</script>