1

In this Django program the checkbox in the form is not shown. I want to show it.

Please explain what is my error.

Django version 1.10.3.

I tried to render the form this way:

class MyForm(forms.Form):
    name = forms.CharField(label='Organization name')
    email = forms.EmailField(label='Organization email')
    trial_period = forms.CheckboxInput()

# The view method
def test(request):
    return HttpResponse(str(checkbox_test.forms.MyForm()))

The view shows name and email but no checkbox for trial_period.

3
  • Can you write down what have you tried so far? Commented Mar 5, 2017 at 21:32
  • Try adding a widget to your form: https://docs.djangoproject.com/en/1.10/ref/forms/widgets/#checkboxinput Commented Mar 5, 2017 at 21:46
  • @joshlsullivan I don't understand what you mean by "adding a widget to your form". Your link points to CheckboxInput class which I already use. So I don't understand what you suggest to add Commented Mar 5, 2017 at 21:55

1 Answer 1

2

forms.CheckboxInput is a widget - not a form field.

I think what you're looking for is a forms.BooleanField

class MyForm(forms.Form):
    name = forms.CharField(label='Organization name')
    email = forms.EmailField(label='Organization email')
    trial_period = forms.BooleanField()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.