'str'对象没有属性'as_widget'

时间:2019-06-12 07:39:10

标签: python django django-forms django-templates

我已经在django中创建了一个表单,并添加了模板标签Add_attr,问题是我遇到了这些错误。

'str' object has no attribute 'as_widget'

{{ form.session_type|add_class='form-control' }}

模板标签:

from django import template

register = template.Library()

@register.filter(name='add_attr')
def add_attr(value, arg):
return value.as_widget(attrs={'class': arg})

editSession.html

  <div class="form-group">
          <label for="exampleInputEmail2">Session Type</label>
                  <span class="input-icon icon-right">

           {{form.session_type|add_attr:"class=form-control"}}

                  </span>
    </div>

views.py

class sessionpdate_view(UpdateView):
model = Session
fields = '__all__'
template_name = 'myapp/editSession.html'

success_url = '/sessionDetail/'

0 个答案:

没有答案