1

它应该很简单,但我找不到如何检查是否选择了一个单选按钮

class ViewSettingsForm (forms.Form):

  CHOICES=[('select1','select 1',),
         ('select2','select 2'),  ('select3','select 3')]

    like = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect())
    name = forms.ChoiceField()


def view_settings (request) :
     owner = request.user
     if request.POST:
          # ??? How to check that something was selected
     else :
         form = ViewSettingsForm ()
4

1 回答 1

0

尝试这个:

try:
    print request.POST.get('like')
except:
    print "nothing was selected" 
于 2013-09-22T14:25:28.703 回答