The issue is the Delete Buttons are not working well, so if I am clicking on Delete Title 1 is deleting Title 1 if I am clicking on Delete Title 2 is deleting Title 1.
This is the code:
@app.route('/addv/<int:users_id>')
def ca_e_5(users_id):
if 'CM' in current_user.access:
return redirect(url_for('cmcp', _external=True))
sca5 = Kca5.query.filter( Kca5.users_id == users_id ).filter( Kca5.ca_st.in_(["a"])).order_by(desc(Kca5.date_posted)).limit(5)
return render_template('ca/e/ca_e_5.html', sca5=sca5)
@app.route("/uad1", methods=["POST"])
def del_ad1st():
try:
nst = request.form.get("nst")
ost = request.form.get("ost")
ctca5 = Kca5.query.filter_by(ca_st=ost).first()
ctca5.ca_st = nst
db.session.commit()
except Exception as e:
print("Couldn't delete!")
print(e)
return redirect(url_for('rdr', _external=True))
This is the html code:
<form method="POST" action="{{ url_for('del_ad1st') }}">
<input type="hidden" value="{{ctca5.ca_st}}" name="ost">
<input type="hidden" value="b" name="nst">
<button type="submit" class="btn btn-danger btn-xs" ><i class="fa fa-trash"style="color:white"></i> Delete {{ ctca5.ca_vcn[:100] | safe }} <i class="fa fa-arrow-up"style="color:white"></i></button>
</form>
formaction
s?del_ad1st
function deletes the first title always. So if the buttons both call that function (url) they will perform the same action.