我已经在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/'