问题
I was trying include a checkbox on my template, but it showed me some text on the browser instead.
I have a form (forms.py) that contains boolean field, e.g:
Class MyForm(forms.Form):
my_checkbox = forms.BooleanField(required=False, label='my_checkbox'),
and I have the following in my templates/my_app/my_form_template.py:
<form id="form" method="post">
{{ form.my_checkbox }}
<form>
In the browser after running the server, I've got:
(<django.forms.fields.BooleanField object at 0x0000014BE3CF9208>,)
The CharField and ChoiceField work perfectly except BooleanField. What is a way to represent a checkbox on the template?
I've tried {{ form }} in the template and it shows the checkbox, but I wish to custom the attributes of the checkbox.
回答1:
There is a comma at the end of the field that causes an error. Removing it would fix the problem.
来源:https://stackoverflow.com/questions/57314626/django-the-page-shows-django-forms-fields-booleanfield-object-at-at-v