@app.route(\'/profile\',methods=[\'POST\',\'GET\'])
def profile(id):
id13=session[\'id\']
id_profile=id
search=None
row=None
Only one form can be submitted by the browser. You're trying to process the data from both, but the non-submitted data won't exist in request.form
and will raise a 400 error.
You need to be able to distinguish which form was submitted. Add a name and value to the submit button and check which value was returned to know what processing to do. You were on the right track by adding buttons with names, but you weren't consistent about them and weren't checking their value in Flask.
<!-- in the search form -->
<button type=submit name=action value=search>
<!-- in the second form -->
<button type=submit name=action value=comment>
if request.method == 'POST':
if request.form['action'] == 'search':
# do search action
elif request.form['action'] == 'comment':
# do comment action
In this case, it makes more sense to have different views handling searching and commenting. Create two separate views, and point the forms at the correct URLs.
<form method=post action="{{ url_for('search') }}">
<form method=post action="{{ url_for('comment') }}">