how to get class/id name from template (django) on post -


i need id of object clicked can use in query in view.

template

<form action="/services/delpoll/" method="post">{% csrf_token %}        <td><input type="submit" id="{{b.id}}" class="delete_poll" value="borrar"></td>      </form> 

view

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 snmptt_listpolls 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'} )   

try this:

<button type="submit" value="{{b.id}}" name="id_value" class"delete_poll">borrar</button> 

then in view:

request.post.get("id_value", "") 

read can too. django doc


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -