如何通过小部件属性传递模板参数

时间:2019-01-07 10:07:55

标签: django django-models django-forms django-templates django-views

我想从小部件attr形式传递上下文。例子

self.fields ['accesses']。widget.attrs ['value'] ='{{company.id}},{{functionality.id}}'

class ACLFormAdd(forms.Form):
        accesses = forms.BooleanField(required=False)

        def __init__(self, *args, **kwargs):
            super(ACLFormAdd, self).__init__(*args, **kwargs)
            self.fields['accesses'].widget.attrs['name'] = 'accesses'
            self.fields['accesses'].widget.attrs['value'] = '{{company.id}},{{functionality.id}}'

0 个答案:

没有答案