如何在django中进行预先选中的复选框? [英] How to make pre-selected checkbox in django?
本文介绍了如何在django中进行预先选中的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单有 CheckboxSelectMultiple
widget接收用户的偏好设置。
我想向用户显示一个预先选中的首选项。
我知道有一种方法来预先检查模板中的小部件。
但是我想知道一种单独预先检查视图的方法。
我该怎么做?
My form has CheckboxSelectMultiple
widget receiving user's preferences.
I want to show a pre-checked preference to user.
I know there is one way to pre-check widget in the template.
But I want to know a way to pre-check in the view individually.
How can I do that?
推荐答案
只需将要检查的值传递给 initial
(见文档)当您实例化表单时:
Just pass the values you want to be checked to initial
(see docs) when you instantiate the form:
MyForm(initial={
'my_multi': ['a', 'b', 'c']
})
这篇关于如何在django中进行预先选中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文