How do I use Django's form framework for select options?

后端 未结 4 1090
旧巷少年郎
旧巷少年郎 2021-02-12 15:15

http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Select

Here, it says I can do SELECT widgets. But how do I do that? It doesn\'t show any example on

4条回答
  •  忘掉有多难
    2021-02-12 15:23

    class MyForm(forms.Form):
        CHOICES = (('Option 1', 'Option 1'),('Option 2', 'Option 2'),)
        field = forms.ChoiceField(choices=CHOICES)
    
    print MyForm().as_p()
    
    # out: 

提交回复
热议问题