python - To edit data retrieved from database in django -
I have retrieved the data from the database and displayed it in a table. Now click the edit button I edit the table Want to Below is my code but nothing is happening. I am unable to edit the content. No error is found. I'm a newbie. PRG help ..
My views.py file
def editquestiondata (request, id): info = Trans.objects. get (pk = id) info.transtype_id = Request.POST.get ('editexplain') info.save () Return HttpResponse ('Update') My urls.py file
url (R '^ editquestiondata / $', 'booki.account.views.editquestiondata', name = 'editquestiondata'), HTML template
& lt; Table range = "1" style = "width: 800px" & gt; & Lt; Button Type = "Button" value = "Explain Edit" name = "editexplain" & gt; Edit & lt; / Button & gt; & Lt; Button type = "button" onclick = "warning ('changes saved!')" & Gt; Save & lt; / Button & gt; & Lt; TR & gt; In {% for questdata%} & lt; / Tr & gt; & Lt; TR & gt; & Lt; TD & gt; {{s.script}} & lt; / Td> & Lt; TD & gt; {{s.id}} & lt; / Td> & Lt; / TR & gt; {% Endfor%} & lt; / Table & gt;
response found ...
My HTML template
Enter code here & lt ;! Doctype html & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt; Table range = "1" style = "width: 900px" & gt; & Lt; TR & gt; {% Of details in%} & lt; / Tr & gt; & Lt; Form action = "method =" POST "& gt; & Lt; Input type = "hidden" value = {{s.id}} name = "sid" /> & Lt; TR & gt; & Lt; TD & gt; {{S.script}} {% if s.id == sid%} & lt; Input type = "text" name = "script" value = "{{s.script}}" /> {% Endif%} & lt; / Td> & Lt; TD & gt; & Lt; A href = "/ accounts / newexplain /? Sid = {{s.id}}" & gt; Edit & lt; / A & gt; & Lt; / TD & gt; & Lt; / Form & gt; & Lt; / TR & gt; {% Endfor%} & lt; / Table & gt; & Lt; / Body & gt; & Lt; / Html & gt; Enter the file of my derivative DRF editexplain (request): info = Trans.objects.all () if request.POST: sid = Request Edit.poast.get ('sid') Edit = info.get (sid = s.id) Edit = request.POST.get ('script') edit.save () Return Render (Request, 'newexplain.html' , {'Info': info, 'sid': sid})
Comments
Post a Comment