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

后端 未结 4 1074
旧巷少年郎
旧巷少年郎 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:33

    errx's solution was almost correct in my case, the following did work (django v1.7x):

    CHOICES= (
    ('1','ME'),
    ('2','YOU'),
    ('3','WE'),
    )
    select = forms.ChoiceField(widget=forms.Select, choices=CHOICES)
    

    The elements inside CHOICES correspond to ($option_value,$option_text).

提交回复
热议问题