title: Add custom CSS styling to model form django
body: <p>I am using a bootstrap variant to help style a model form. There is a certain class I would like one of the fields to be and I have read around on the subject and the general consensus is to add a widget to the ModelForm's meta, like I tried below:</p>
  
  <p>forms.py</p>
  
  <pre><code>class EmailForm(forms.ModelForm):
      class Meta:
          model = MarketingEmails
          fields = ['messageid','subject','body','name','altsubject','utm_source','utm_content','utm_campaign',]
          widgets = {
              'body': Textarea(attrs={'class': 'summernote'}),
          }
  </code></pre>
  
  <p>However this doesn't seem to render onto my template, which is:</p>
  
  <pre><code>&lt;div class="row"&gt;
  &lt;div class="col-sm-6"&gt;
      &lt;form method="POST" class="post-form" action =""&gt;
      {% csrf_token %}        
          &lt;p&gt;&lt;label for="id_subject"&gt;Subject&lt;/label&gt;
          &lt;input class="form-control" id="id_subject" type="text" name="subject" maxlength="1000" value="{{rows.subject}}"required /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="id_name"&gt;Name&lt;/label&gt;
          &lt;input class="form-control" id="id_name" type="text" name="name" maxlength="1000" value="{{rows.name}}"required /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="id_body"&gt;Body&lt;/label&gt;
          &lt;input class="form-control" id="id_body" type="text" name="body" maxlength="1000" value="{{rows.body}}"required /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="id_altsubject"&gt;Alt Subject&lt;/label&gt;
          &lt;input class="form-control" id="id_altsubject" type="text" name="altsubject" maxlength="1000" value="{{rows.altsubject}}"required /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="id_utm_source"&gt;utm_source&lt;/label&gt;
          &lt;input class="form-control" id="id_utm_source" type="text" name="utm_source" maxlength="1000" value="{{rows.utm_source}}"required /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="id_utm_content"&gt;utm_content&lt;/label&gt;
          &lt;input class="form-control" id="id_utm_content" type="text" name="utm_content" maxlength="1000" value="{{rows.utm_content}}"required /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="id_utm_campaign"&gt;utm_campaign&lt;/label&gt;
          &lt;input class="form-control" id="id_utm_campaign" type="text" name="utm_campaign" maxlength="1000" value="{{rows.utm_campaign}}"required /&gt;&lt;/p&gt;
  
          &lt;button type="submit" class="save btn btn-default"&gt;Save&lt;/button&gt;
  
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Is there another way to do this or is there something I have done wrong in my code?</p>
  
  <p><strong>UPDATE</strong>
  I have followed the suggested of Jacek and now it is styled but the information is no longer displaying, this is my new code:</p>
  
  <p>forms.py:</p>
  
  <pre><code>class EmailForm(forms.ModelForm):
  subject = forms.CharField(
      label = 'Subject',
      max_length = 2000,
      required = True,
      widget = forms.TextInput(
          attrs = {'class': 'summernote', 'name': 'subject'}
          )
      )
  
  ... 
  class Meta:
      model = MarketingEmails
      fields = ['messageid','subject','body','name','altsubject','utm_source','utm_content','utm_campaign',]
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>def emailinfo(request, pk):
  if request.session.has_key('shortname'):
      shortname =  request.session['shortname']
      form = MarketingEmails.objects.filter(messageid =pk).get()
      if request.method == 'GET':
          form = EmailForm(instance=form)
          return render(request, 'marketingemails/emailinfo.html',{'shortname': shortname, 'form': form})
  
      else:
          form = EmailForm(request.POST,instance=form)
          if form.is_valid():
              return redirect('marketingemails:emailinfo', pk = form.messageid)
  
      return render(request, 'marketingemails/emailinfo.html',{'shortname': shortname, 'form': form})
  else:
      return HttpResponseRedirect(reverse('common:login'))    
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>&lt;div class="row"&gt;
  &lt;div class="col-sm-6"&gt;
      &lt;form method="POST" action =""&gt;
      {% csrf_token %}        
      {% for field in form %}
          {{ field.label_tag }}
          {{ field }}
  
          {% if field.help_text %}
              {{ field.help_text }}
          {% endif %}
  
          {% for error in field.errors %}
              {{ error }}
          {% endfor %}
  
      {% endfor %}
      &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
  
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>