Django jinja2 'BoundField' 对象没有属性 '__call__'
Django jinja2 'BoundField' object has no attribute '__call__'
为什么我会收到此错误:
'BoundField' object has no attribute '__call__'
我在jinja2.py中有功能:
class SimpleFilterForm(forms.Form):
name = fields.CharField(label=_(u'Reči'), required=False)
parent_category = models.ModelChoiceField(label=_(u'Kategorija'), queryset=Category.objects.filter(parent__isnull=True), required=False, empty_label='')
category = MyMultipleChoiceField(label=_(u'Pod kategorije'), queryset=Category.objects.none(), required=False)
city = models.ModelMultipleChoiceField(label=_(u'Gradovi'), queryset=City.objects.all(), required=False)
ad_type = fields.IntegerField(widget=widgets.HiddenInput(), required=False)
price__gte = fields.DecimalField(label=_(u'Cena od'), required=False, widget=widgets.TextInput(), localize=True)
price__lte = fields.DecimalField(label=_(u'Cena do'), required=False, widget=widgets.TextInput(), localize=True)
currency = models.ModelChoiceField(label=_(u'Valuta'), queryset=Currency.objects.all(), to_field_name='code', required=False, empty_label='')
def cat_filter_form_tag(request, parent_category):
filter_form = SimpleCatFilterForm(parent_category, request.GET)
return render(request, 'web/category_ads/filter_form.html', {"filter_form": filter_form})
def environment(**options):
env = Environment(**options)
env.globals.update({
'cat_filter_form_tag': cat_filter_form_tag,
})
return env
编辑:
模板:
<div class="sidebox filter-form">
<h5><span class="fa fa-search"></span> {{ trans('Pretraga') }}</h5>
<form action="">
<div class="form-group">
{{ filter_form.name(class="form-control") }}
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary btn-block" value="{{ trans('Traži') }}">
</div>
</form>
</div>
此 "name" 字段有错误。
在 django 模板中它工作正常,但在 jinja2 中它不能。
您没有调用字段,也没有通过模板向其添加 类;你在表单定义中这样做:
name = fields.CharField(label=_(u'Reči'), required=False, widget=forms.TextInput(attrs={'class': 'form-control'}))
并且您只需使用模板中的属性:
{{ filter_form.name }}
注意,这里 Jinja 和 Django 模板没有区别。
为什么我会收到此错误:
'BoundField' object has no attribute '__call__'
我在jinja2.py中有功能:
class SimpleFilterForm(forms.Form):
name = fields.CharField(label=_(u'Reči'), required=False)
parent_category = models.ModelChoiceField(label=_(u'Kategorija'), queryset=Category.objects.filter(parent__isnull=True), required=False, empty_label='')
category = MyMultipleChoiceField(label=_(u'Pod kategorije'), queryset=Category.objects.none(), required=False)
city = models.ModelMultipleChoiceField(label=_(u'Gradovi'), queryset=City.objects.all(), required=False)
ad_type = fields.IntegerField(widget=widgets.HiddenInput(), required=False)
price__gte = fields.DecimalField(label=_(u'Cena od'), required=False, widget=widgets.TextInput(), localize=True)
price__lte = fields.DecimalField(label=_(u'Cena do'), required=False, widget=widgets.TextInput(), localize=True)
currency = models.ModelChoiceField(label=_(u'Valuta'), queryset=Currency.objects.all(), to_field_name='code', required=False, empty_label='')
def cat_filter_form_tag(request, parent_category):
filter_form = SimpleCatFilterForm(parent_category, request.GET)
return render(request, 'web/category_ads/filter_form.html', {"filter_form": filter_form})
def environment(**options):
env = Environment(**options)
env.globals.update({
'cat_filter_form_tag': cat_filter_form_tag,
})
return env
编辑:
模板:
<div class="sidebox filter-form">
<h5><span class="fa fa-search"></span> {{ trans('Pretraga') }}</h5>
<form action="">
<div class="form-group">
{{ filter_form.name(class="form-control") }}
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary btn-block" value="{{ trans('Traži') }}">
</div>
</form>
</div>
此 "name" 字段有错误。
在 django 模板中它工作正常,但在 jinja2 中它不能。
您没有调用字段,也没有通过模板向其添加 类;你在表单定义中这样做:
name = fields.CharField(label=_(u'Reči'), required=False, widget=forms.TextInput(attrs={'class': 'form-control'}))
并且您只需使用模板中的属性:
{{ filter_form.name }}
注意,这里 Jinja 和 Django 模板没有区别。