Issue
I want to insert data into the database. But I got a problem that the browser (or proxy) sent a request that this server could not understand.
KeyError at 'parcel_idi'
1.from.html
<form action="{{ url_for('insert') }}" method="post">
<div class="form-group">
<label for="parcel_idi">ID</lable>
<input type="text" class="form-control" name="parcel-idi"></input>
</div>
<div class="form-group">
<label for="parcel_name">Name</lable>
<input type="text" class="form-control" name="parcel_name"></input>
</div>
<div class="form-group">
<label for="unit">Unit</lable>
<input type="text" class="form-control" name="unit"></input>
</div>
<button type="submit" class="pull-left btn btn-success">ADD +</button>
</form>
2.app.py
@app.route("/insert",methods=['POST'])
def insert():
if request.method=='POST':
parcel_idi=request.form['parcel_idi']
parcel_name=request.form['parcel_name']
unit=request.fomr['unit']
with conn.cursor() as cursor:
sql="INSERT INTO `parcel_table` (`parcel_idi`, `parcel_name`, `unit`) VALUES ('%s', %s', '%s')"
cursor.execute(sql(parcel_idi,parcel_name,unit))
conn.commit()
return redirect(url_for('parcel1'))
Happens when I go to submit the form, can view the form no problem
Solution
Update the name field in text box "parcel-idi" to "parcel_idi".
<input type="text" class="form-control" name="parcel-idi"></input>
<input type="text" class="form-control" name="parcel_idi"></input>
Answered By - Praba karan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.