title: Django 'str' object has no attribute 'as_widget'
body: <p>I've made a register form in django and i've created a template tag <code>add_class</code> to create users, the problem is i'm getting this error:</p>
  
  <pre><code>'str' object has no attribute 'as_widget'
  </code></pre>
  
  <p>to</p>
  
  <pre><code>{{ form.username|add_class:'form-control' }}
  </code></pre>
  
  <p>register_user.html</p>
  
  <pre><code>&lt;form class="form-horizontal" method="POST" action=""&gt;
      {% csrf_token %}
      {% if form.errors %}
          &lt;p&gt;Your username and password didn't match. Please try again.&lt;/p&gt;
      {% endif %}
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-12"&gt;
              {{ form.username|add_class:'form-control' }}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-12"&gt;
              {{ form.email|add_class:'form-control' }}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-12"&gt;
              {{ form.password|add_class:'form-control' }}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-12"&gt;
              {{ form.confirm_password|add_class:'form-control' }}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-12"&gt;
              &lt;button type="submit" class="btn btn-info btn-block"&gt;Register&lt;/button&gt;
              &lt;input type="hidden" name="next" value="{% url 'register_user_success' %}"/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>form.py</p>
  
  <pre><code>class UserForm(ModelForm):
      username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Username'}))
      password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
      email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'E-mail'}))
      confirm_password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'}))
  
      class Meta:
          model = CustomUser
          fields = ('username', 'email', 'password', 'confirm_password')
  
      def clean(self):
          cleaned_data = super(UserForm, self).clean()
          password = cleaned_data.get('password')
          confirm_password = cleaned_data.get('confirm_password')
          if password != confirm_password:
              raise forms.ValidationError('Password did not match.')
  </code></pre>
  
  <p>template tag: my_filters.py</p>
  
  <pre><code>from django import template
  
  register = template.Library()
  
  
  @register.filter(name='add_class')
  def add_class(value, arg):
      return value.as_widget(attrs={'class': arg})
  </code></pre>
  
  <p>I've made the template tag so i can add classes from css.</p>
  
  <p>views.py</p>
  
  <pre><code>def register_user(request):
      data = dict()
      if request.method == 'POST':
          form = UserForm(request.POST)
          if form.is_valid():
              user = form.save(commit=False)
              user.set_password(user.password)
              user.save()
              return redirect('/register_user/success/')
      else:
          data['form'] = UserForm()
      return render(request, 'register_user.html', data)
  </code></pre>