我需要獲取單擊對象的id,以便我可以在視圖中的查詢中使用它。如何從模板(django)上獲得類/ id名
模板
<form action="/services/delpoll/" method="post">{% csrf_token %}
<td><input type="submit" id="{{b.id}}" class="delete_poll" value="Borrar"></td>
</form>
視圖
def delpoll(request):
connect_mysql = mdb.connect('*', '*', '*', '*')
cursorMYSQL = connect_mysql.cursor(mdb.cursors.DictCursor)
if request.method == 'POST':
id_poll = request.POST.get['delete_poll'];
cursorMYSQL.execute(""" delete from snmptt_listpolls where id='%s' """%(id_poll))
connect_mysql.commit()
connect_mysql.close()
return render_to_response("delpoll.html",{"message": 'post'})
else:
return render_to_response("delpoll.html",{"message": 'no-post'})
id_poll有什麼價值? –
這是聲明那裏,我想保存在該變量 –