samedi 6 mars 2021

400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'nameSearch'

I have checked everything and i keep getting this error, i dont know whats wrong

<form action="/findafriend" method="POST">
    <input type="text" name="nameSearch">
    <input type="submit" value="Search">
</form>

    <h2>
        
    </h2>
</body>
    @app.route('/findafriend', methods=['POST', 'GET'])
def findFriend():
    if request.method == "POST":
    
    
    
    
        return redirect('/findafriend')
    else:
        findFriend = request.form["nameSearch"]
    
        oneItem = Friends.query.filter_by(findFriend).all 
        return render_template('findafriend.html', oneItem=oneItem, foundFriend=foundFriend, 
findFriend=findFriend)

As you can see

findFriend = request.form["nameSearch"]

should work since "nameSearch" is the smae as in the html form

but i am pretty sure there is something wrong in the other part of the python code but im not sure what since i am a newbie




Aucun commentaire:

Enregistrer un commentaire