django bootstrap forms.py form.is_valid()无效

时间:2015-07-17 21:13:06

标签: python html django twitter-bootstrap

我的forms.py中有两个字段(下拉列表和textarea)。当我发布一些内容时,流程会转到我的views.py,而editform.is_valid()似乎不起作用。

附件是我的forms.py: -

from django import forms
from functools import partial
import datetime


today = datetime.date.today().strftime("%Y-%m-%d")
TEST_CHOICES = (
    ('1', 'Pass',),
    ('2', 'Fail',),
)

class DateSelectForm(forms.Form):

    testingDate = forms.DateField(widget=forms.TextInput(attrs=
                                {
                                    'class':'datepicker',
                                    'placeholder' : today,
                                    'format': '%Y-%m-%d',
                                }))


class DateSelectAutoForm(forms.Form):

    testingDate = forms.DateField(widget=forms.TextInput(attrs=
                                {
                                    'class':'datepicker',
                                    'placeholder' : today,
                                }))

class DateSelectManForm(forms.Form):

    testingDate = forms.DateField(widget=forms.TextInput(attrs=
                                {
                                    'class':'datepicker',
                                    'placeholder' : today,
                                }))

class EditForm(forms.Form):
    select = forms.ChoiceField(required=True,label='Please select', choices=TEST_CHOICES,
                                       widget=forms.Select(attrs=
                                    {
                                        'class':'selector',
                                        'placeholder':'Please select',
                                    }))
    comment = forms.CharField(required=True,widget=forms.Textarea(attrs=
                                {
                                    'class':'comment',
                                }))

我的forms.py代码段是: -

def manualsubmit(request):

    form = DateSelectForm(request.POST)
    editform = EditForm(request.POST)
    print editform
    if request.method == "POST":
        if editform.is_valid(): 
            print 'inside'
            select = editform.cleaned_data['select']
            comment = editform.cleaned_data['comment']
            print select
            print "select"
    return render_to_response("manTest.html", {'form':form, 'editform':editform}) 

html部分(manTest.html): -

    {% else %}
                  <td width="15%">
                  <form id="form_edit" method="post" action="/manualsubmit/"> 
                   {{ editform.select }} 
                  </td>
                  <td>
                  {{ editform.comment }}
                  </td>
               {% endif %}
               </tr>
      {% endfor %}
   {% endfor %}
      </table>
   {% if todayDate == testingDate %}
   {% buttons %}
    <button type="submit" class="btn btn-primary">
      {% bootstrap_icon "star" %} Submit
    </button>
  {% endbuttons %}
  </form>

0 个答案:

没有答案