sending the data from form to db in django

Posted by BharatKrishna on Stack Overflow See other posts from Stack Overflow or by BharatKrishna
Published on 2010-04-15T13:12:44Z Indexed on 2010/04/15 17:23 UTC
Read the original article Hit count: 150

Filed under:
|

I have a form in which I can input text through text boxes. How do I make these data go into the db on clicking submit.

this is the code of the form in the template.

<form method="post" action="app/save_page">
<p>
Title:<input type="text" name="title"/>
</p>
<p>
Name:<input type="text" name="name"/>
</p>
<p>
Phone:<input type="text" name="phone"/>
</p>
<p>
Email:<input type="text" name="email"/>
</p>
<p>
<textarea name="description" rows=20 cols=60>
</textarea><br>
</p>
<input type="submit" value="Submit"/>
</form>

I have a function in the views.py for saving the data in the page. But I dont know how to impliment it properly:

def save_page(request):
   title = request.POST["title"]
   name = request.POST["name"]
   phone = request.POST["phone"]
   email = request.POST["email"]
   description = request.POST["description"]

Now how do I send these into the db?

And what do I put in views.py so that those data goes into the db? so how do I open a database connection and put those into the db and save it?

should I do something like :

connection=sqlite3.connect('app.db')
cursor= connection.cursor()
.....
.....
connection.commit()
connection.close()

Thank you.

© Stack Overflow or respective owner

Related posts about django

Related posts about python