hello everyone Im trying to send data from a HTML form to a flask backend file and its really simple
the html file contains a simple form that has only one text input and a submit button.
this is the html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form id="sign-form" method="POST">
<input type="text" id="sign-username">
<input type="submit">
</form>
</body>
</html>
plain and simple
and the flask code:
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def home():
sign_user = None # Initialize sign_user (optional)
if request.method == 'POST':
try:
sign_user = request.form['sign-username']
print(f"Received sign-user: {sign_user}") # Print the retrieved value
except KeyError:
print(f"Error: Username field not found in form data.{request.form}")
return render_template("test.html", sign_user=sign_user)
if __name__ == "__main__":
app.run(debug=True)
the problem is that the data in sign-username wont get passed to the flask file.
what can cause the problem?
the post request will be send but the data wont reach the flask file and when i print the request.form its output is ImmutableMultiDict([])? both files are running on the local host http://127.0.0.1:5000