从 ChoiceField 访问特定选择小部件/字段
无论如何要访问小部件/从 ChoiceField 中呈现特定选择?
APPROVAL_CHOICES = (
('true', 'Approve'),
('false', 'Re-Submit')
)
class ProofApprovalForm(forms.Form):
approved = forms.ChoiceField(
choices=APPROVAL_CHOICES,
widget=forms.widgets.RadioSelect
)
想要单独访问模板中的选项。
{{ form.approved.choices.true }}
将渲染真正的小部件 ...
我可以手动渲染它们,但想看看是否有处理这种情况的更干净的 pythonic/django 方式。
Anyway to access the widget/render a specific choice from a ChoiceField?
APPROVAL_CHOICES = (
('true', 'Approve'),
('false', 'Re-Submit')
)
class ProofApprovalForm(forms.Form):
approved = forms.ChoiceField(
choices=APPROVAL_CHOICES,
widget=forms.widgets.RadioSelect
)
Would like to access the choices in the template separately.
{{ form.approved.choices.true }}
Would render the true widget <input type="radio" value="true" name="approved_0" />
...
I could render them manually, but want to see if there is a cleaner pythonic/django way of handling this situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅用于使用重载的
render()
方法创建您自己的小部件或字段Only to create your own widget or field with overloaded
render()
method