jquery - insert / delete post requests in same template django -


i have table showing data , have form submit button inserts data in mysql db, added buttons next each row "delete" i'm able delete each row site too.

i id when click button don't know yet how pass views, main problem second post isn't working.

template.py

<tr>      <td>{{b.ip}}</td>      <td>{{b.polling_time}}</td>      <td>{{b.communitydata}}</td>      <td>{{b.snmp_oid}}</td>      <td>{{b.lastcheck|date:"y.m.d h:m:s"}}</td>      <form action="/services/listpoll/" method="post">{% csrf_token %}        <td><input type="button" id="{{b.id}}" class="delete_poll" value="borrar"></td>      </form>  </tr> 

jquery

$(".delete_poll").click(function(){            id_poll = $(this).attr('id');    }); 

views.py

def listpolls(request):     connect_mysql = mdb.connect('***', '***', '***', '***')     cursormysql = connect_mysql.cursor(mdb.cursors.dictcursor)     query = "select id,ip,polling_time,communitydata,snmp_oid,lastcheck snmptt_listpolls order ip desc limit 100"     cursormysql.execute(query)     b = cursormysql.fetchall()     connect_mysql.close()      if request.method == 'post':          form = addpollform(request.post)          if form.is_valid():              ip = form.cleaned_data['poll_ip']             poll_time = form.cleaned_data['poll_time']             communitydata = form.cleaned_data['communitydata']             snmp_oid = form.cleaned_data['snmp_oid']             lastcheck = form.cleaned_data['lastcheck']              cursormysql = connect_mysql.cursor(mdb.cursors.dictcursor)             cursormysql.execute("""insert snmptt_listpolls (ip, polling_time, communitydata, snmp_oid) values ('%s','%s','%s','%s')"""%(ip, poll_time, communitydata, snmp_oid))              connect_mysql.commit()             connect_mysql.close()              return httpresponseredirect('listpolls.html')          elif request.method == 'post' , not form.is_valid():               id_poll = '53';              cursormysql = connect_mysql.cursor(mdb.cursors.dictcursor)             cursormysql.execute(""" delete snmptt_listpolls id='%s' """%(id_poll))              connect_mysql.commit()             connect_mysql.close()              return render_to_response("listpolls.html",{"buffer_data": b, 'form': form} )       else:         form = addpollform()         return render_to_response("listpolls.html",{"buffer_data": b, 'form': form} )  

so, time i'm trying check if post request working when click delete row 53 id, doesn't work, guess i'm doing wrong , post not going through.

thanks!

i can't comment yet.so please consider comment.

i don't think execution ever reach second post

elif request.method=="post": 

also why don't use django models instead of doing explicitly mysql.

for deleting item can use jquery ajax post request id of item , handle in view.


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 -