Reputation: 1
I made a simple HTML:
<!DOCTYPE html>
<html>
<head>
<title>Form to Post</title>
<form action="post">
<input type="text" name="theinput"><br>
<input type="submit" value="Submit">
</form>
<p>{{theout}}</p>
</head>
<body>
</body>
</html>
All I want t do here s input somethign in the boix and post it right underneath. This is the flask code I am using:
from flask import render_template, request
app = Flask(__name__)
@app.route('/', methods=['GET','POST'])
def homepage():
if request.method == 'POST':
return render_template("index.html", theout=theinput)
else:
return render_template("index.html")
if __name__ == "__main__":
app.run()
What am I doing wrong here? (The HTML IS index.html)
Upvotes: 0
Views: 59
Reputation: 324
The action
attribute should be the URL you want to POST to, while the method
attribute should be the method you want to use. So in your case, it would be:
<form action="/" method="post">
In flask, you need to make sure you get all the form fields through the requests
module. After importing it, get the form field data by:
theinput = request.form['theinput']
Upvotes: 2
Reputation: 354
You have to use <form action="/" method="POST>.....</form>
, not action="post"
Action corresponds to the destination route for the desired HTTP Request.
Upvotes: 0