Radio buttons in django Forms

Look at setting the field’s widget and choices when writing the form class.

from django import forms

class PictureForm(forms.Form):
    CHOICES = [
        ('1', 'Option 1'),
        ('2', 'Option 2'),
    ]
    like = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=CHOICES, 
    )
  • The default widget of ChoiceField is a drop down select.
  • The choices argument has the same format as the one of a model field.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)