Feb-09-2021, 09:05 AM
Hi!
There is a html file, with two separate <form(s)>.
How to get the data from both?
There is a html file, with two separate <form(s)>.
How to get the data from both?
from flask import Flask, request, render_template, url_for app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def two_separate_forms(): if request.method == 'POST': data = request.form print(data) return render_template('test.html') if __name__ == '__main__': app.run()
Output:############ HTML #################
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<form action="{{ url_for('two_separate_forms') }}" method="post">
<input type="text" name="firstname" value="John"><br>
<input type="submit" name="get_both_data" value="Send all data">
</form>
<form action="{{ url_for('two_separate_forms') }}" method="post">
<input type="text" name="familyname" value="Smith"><br>
</form>
</body>
</html>