Django:该页面显示“((...的django.forms.fields.BooleanField对象))"在模板中的可变位置 [英] Django: The page shows "(<django.forms.fields.BooleanField object at ...>)" at variable location in a template

查看:44
本文介绍了Django:该页面显示“((...的django.forms.fields.BooleanField对象))"在模板中的可变位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在模板上包含一个复选框,但它却在浏览器上显示了一些文本.

I was trying include a checkbox on my template, but it showed me some text on the browser instead.

我有一个包含布尔字段的表单(forms.py),例如:

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'),

并且我的模板/my_app/my_form_template.py中包含以下内容:

and I have the following in my templates/my_app/my_form_template.py:

<form id="form" method="post">
    {{ form.my_checkbox }}
<form>

运行服务器后,在浏览器中,我得到:(< django.forms.fields.BooleanField对象位于0x0000014BE3CF9208>,)

In the browser after running the server, I've got: (<django.forms.fields.BooleanField object at 0x0000014BE3CF9208>,)

CharField和ChoiceField可以完美运行,但BooleanField除外.在模板上表示复选框的方式是什么?

The CharField and ChoiceField work perfectly except BooleanField. What is a way to represent a checkbox on the template?

我在模板中尝试过{{form}},它显示了复选框,但是我希望自定义复选框的属性.

I've tried {{ form }} in the template and it shows the checkbox, but I wish to custom the attributes of the checkbox.

推荐答案

该字段的末尾有一个逗号,该错误会导致错误.删除它可以解决问题.

There is a comma at the end of the field that causes an error. Removing it would fix the problem.

这篇关于Django:该页面显示“((...的django.forms.fields.BooleanField对象))"在模板中的可变位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆