1

I need the code for updating data to database(mysql) through html submit button in Python/Django.need view.py contents with html code.consider I am having a table with bookname,authorname & publishername i need to update the values these values through an html submit button.

Plese help me in this..I am new to this framework...not able to get through.

It will be more thankfull if you send me a code for edit a table in mysql througn Django/Python

1 Answer 1

2

models.py

class Book(models.Model):
   book_name = models.CharField(max_length = 32, unique = True)
   author_name = models.CharField(max_length = 32, unique = True)
   publisher_name = models.CharField(max_length = 32, unique = True)

forms.py

import Book from your path

class BookForm(forms.ModelForm):
   class = Book

view.py

def save_book(request):  
  form = BookForm
  if request.POST:
     form = BookForm(request.POST)
     if form.is_valid():
        form.save()
  return render_to_response('book.html.html',{'form': form} ,                 context_instance=RequestContext(request))

book.html

<body>
<form action="." method="post" name="book" id="book">{% csrf_token %}
<table>
<tr><td>{{form.book_name.label}}</td><td>{{form.book_name}}</td></tr>
<tr><td>{{form.author_name.label}}</td><td>{{form.author_name}}</td></tr>
<tr><td>{{form.publisher_name.label}}</td><td>{{form.publisher_name}}</td></tr>
<tr><td></td><td><input type="button" name="btnSave" id="bntSave" value="Save"  class = "default2"/></td>
</table>
</body>

url.py call your url

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.