python - to retrieve values of multiple radio buttons and form fields in views.py django -


i want receive radio button values table generated within form multiple times in views.py in django.

my templates file :

<form action = "/appname/accept" method = "post"     {% l in list %}         <table>         <tr>         <td>{{l.value}}</td>          </>tr         </table>           <input type = "radio" name = "acceptance" value ="accept">accept</input>         <input type = "radio" name = "acceptance" value ="reject">reject</input>      {% endfor %}      <input type ="submit" name = "submit">submit</input> </form> 

that means rendered page :

value 1

  • accept

  • reject

value 2

  • accept
  • reject

and on submit button

as user clicks submit button, want collect values of radio buttons each value table rows how in views.py? know if give common name radio input here "acceptance", of 1 of them selected @ time. please help. new concept , django.

you should better use django formsets https://docs.djangoproject.com/en/1.8/topics/forms/formsets/

as mentioned in documentation :

from django.forms.formsets import formset_factory django.shortcuts import render_to_response myapp.forms import articleform  def manage_articles(request):     articleformset = formset_factory(articleform)     if request.method == 'post':         formset = articleformset(request.post, request.files)         if formset.is_valid():             form in formset:                 form.cleaned_data...                 # here can access each radio button       else:         formset = articleformset()     return render_to_response('manage_articles.html', {'formset': formset}) 

the manage_articles.html template might this:

<form method="post" action="">     {{ formset.management_form }}     <table>         {% form in formset %}         {{ form }}         {% endfor %}     </table> </form> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -