将命名置属性添加到django-crispy-Form字段
我试图将名称属性属性(x-bind:attr
)添加到脆皮表单字段中,但找不到有效的解决方案。我知道使用仪表板的属性是通过使用下划线来处理的,我试图通过用双重结肠替换双重下划线来做同样的事情,但它不起作用,也没有替换。
class ChildFormSetHelperUpdate(FormHelper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_tag = False
self.include_media = False
self.layout = Layout(
Div(Field('model', x_bind__disable="disableInput"), css_class='col-md-6'),
)
self.render_required_fields = True```
I was trying to add a namespaced attribute (x-bind:attr
) to a crispy form field but I couldn't find a solution that works. I know that attributes with a dash are handled by using an underscore, I tried to do the same by replacing double underscore with the double colon but it didn't work and no replacement is made.
class ChildFormSetHelperUpdate(FormHelper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_tag = False
self.include_media = False
self.layout = Layout(
Div(Field('model', x_bind__disable="disableInput"), css_class='col-md-6'),
)
self.render_required_fields = True```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在字典中传递关键字参数来实现这一目标,并使用
field
使用**
拆卸操作员:这使您无法使用dashes和colons在Python变量名称中。该属性将被渲染为:
You can achieve this by passing the keyword argument in a dictionary, and expanding that into the kwargs for
Field
using the**
unpacking operator:This gets around the fact that you can't use dashes and colons in Python variable names. The attribute will be rendered as: