I would say the way to handle this is to make all submit controls/buttons have the same name and different value.
Then just act based on what value has been submitted.
Then just act based on what value has been submitted.
from flask import Flask, render_template, request, flash app = Flask(__name__) app.config['SECRET_KEY'] = ',9fB3L,,b&h~?^dy' # as the name suggest this should be a secret. @app.route('/', methods=['POST', 'GET']) def index(): return render_template('index.html') @app.route('/new_page', methods=['POST', 'GET']) def new_page(): actions = {'Add something': 'Adding something', 'List something': 'Listing something', 'Delete something': 'Deleting something'} if request.method == 'POST': flash(actions[request.form['my_btn']]) return render_template('new_page.html') if __name__ == '__main__': app.run()new_page.html:
Output:<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
this is the new page
<br>
<form>
<input type="submit" id="send" name="my_btn" formmethod="post" value="Add something">
<input type="submit" id="send" name="my_btn" formmethod="post" value="List something">
<input type="submit" id="send" name="my_btn" formmethod="post" value="Delete something">
</form>
</body>
</html>
here I use flash message to display the result of button click
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs