Django: The page shows “(<django.forms.fields.BooleanField object at …>)” at variable location in a template

旧街凉风 提交于 2021-02-10 16:51:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!