python - django forms into database -


O people, trying to create a volunteer form, which takes information like name, last name, and me To save that information to your database (MySQL), so that it can be retrieved later.

You will first need to define a model that will keep this information, in the models.py file Something happens in this:

  class.model: def __unicode __ (self): return self fname + self.lname fname = models.CharField (max_length = 200) lname = Models.CharField (max_length = 200) Bio = Model. TextField (max_length = 400) number = model. Rich field (max_length = 15) email = modesl CharField (max_length = 255)  

and then a view to get POST data from view, view .py:

  def volunteer_centre (request): If request.method == 'POST' and request.POST ['fname'] and request it. POST ['lname'] and request POST ['Email'] (ETC ..): V = Volunteer () v.fname = request.POST ['fname'] v.fname = request.POST ['lname'] v.fname = request.POST [ 'Email'] v.fname = Request post ['number'] ... v.save () Returns HTTPPRPS ("Thanks!") #success! Then the HTTPRPSPager Recharge ("/ Volunteer_forms") # to fill the hidden information back to the form  

Then to point to the form target you need to urls.py In this view, you must set up.


Comments