I am trying to get value of apptext from the form in my template, but seems like the request.form doesn't have the 'apptext'.
Body
I am trying to get value of apptext from the form in my template, but seems like the request.form doesn't have the 'apptext'.
This is the part of Flask code that are relevant
@app.route('/', methods = ["GET", "POST"])
def search():
# if request.method == "POST":
app.logger.info(request.form)
app_name = request.form['apptext']
This is the part of the template file
{% extends 'base.html' %}
{% block header %}
<h1>{% block title %}Search Apps{% endblock %}</h1>
{% endblock %}
{% block content %}
<form method="post">
<p><label for="apptext">App text</label></p>
<p><input type="text" id="apptext" name="apptext"></p>
<p><input type="submit" value="Search"></p>
</form>
{% endblock %}
So the path '/' just gave me the error below now:
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'apptext'
1 Replies
Bottom ad position