开发者

Django: Storing values into MySql from Templates

I have used a checkbox in my html template, On submit, i want to store these Boolean values into the MySql Table. Please advice me on, How should i code my views such that 开发者_运维问答it accepts values from Templates and stores it to the database. Also suggest , if any alternative method is possible.


In order to store data into models from the user input, django provides a very good form API called ModelForm.

Documentation: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ clearly illustrates how to do it.

Essentially, you create a form and tell it, the model (which is your mysql table) you need to save it's data to and its all done for you. After validating.


In addition to becomingGuru's answer I think you have to learn how data is transported via HTTP and HTML forms work, i.e. how to process user submitted data at the server side. This is not Django related.

But in Django you can access the data submitted in the views via

request.POST['parameter_name'] # for POST data
# or
request.GET['parameter_name'] # for GET data
# or
request.REQUEST['parameter_name'] # combined list these parameters

then you can store them in your database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜