title: Django add class to form <input ..> field
body: <p>We are looking for a solution to add a CSS class attribute to a Django form's <code>&lt;input..&gt;</code> field.  We've seen the advice that suggests we wrap the field in a <code>&lt;div&gt;</code> <a href="http://docs.djangoproject.com/en/1.2/topics/forms/#customizing-the-form-template" rel="noreferrer">http://docs.djangoproject.com/en/1.2/topics/forms/#customizing-the-form-template</a>, but this advice mainly seems to apply to a fields label, not it's <code>&lt;input ...&gt;</code>. </p>
  
  <p>This particular advice doesn't work if you are trying to create a border around the <code>&lt;input&gt;</code> field. In that case, the <code>&lt;div&gt;</code> will be applied to the bounding box, and not the actual input field. For example <code>.wrapper { border: 1px solid #666;line-height:22px;height:22px;padding:3px 5px;width:205px;}</code> will create a box around the  field, rather than replace the default <code>&lt;input ...&gt;</code> border.</p>
  
  <p>We've fallen back to applying the class through a widget applied to the Form class, but this lacks a certain amount of code elegance (and violates DRY). For example, this solves the need.</p>
  
  <pre><code>class ContactUsForm(forms.Form):
      name = forms.CharField(widget=forms.TextInput(attrs={'class':'form_text'}))
  </code></pre>
  
  <p>But of course, this ties the Form very tightly to the CSS. And it get's even more complex if you are trying to apply class attributes to <code>&lt;input ..&gt;</code> fields if the form is based instead on the cool new forms.ModelForm system.</p>
  
  <p>We've spent the better part of two days playing with this issue (and studying Django source code), and it looks like we may be reaching the farthest edges of Django for this one particular issue -- but we just wanted to take one pass at StackOverflow to see if anyone else had insight.</p>
  
  <p>Thanks for any insight.</p>
  
  <p>One final comment: feel free to set us straight on this if the problem is our understanding CSS (rather than django). We've spent quite a bit of time messing with CSS options, but none of them seem to allow us to accomplish the effect desired -- that is replacing the default <code>&lt;input...&gt;</code> border.</p>