title: Adding a CSS class to fields in django.contrib.auth.views.login
body: <p>I'm still fairly new to django, and have come across Django forms for the first time through my use of the <code>django.contrib.auth.views.login</code> view, used when Django needs a user to authenticate. </p>
  
  <p>I cannot however figure out how to add a CSS class to the username and password fields and the documentation doesn't specify how I can achieve it.  Ideally I'd like to simply add the additional info to the template tag, such as <code>{{ form.username | class="usernameclass" }}</code> or whatever, or even write the field out manually, such as <code>&lt;input type="{{ form.password.type }}" name="{{ form.password.name }}" class="form-field-password"/&gt;</code>, but if I need to add a custom view to achieve this I can try that way.</p>
  
  <p>The files related to this are below:</p>
  
  <p><em>templates/login.html:</em></p>
  
  <pre><code>{% load url from future %}
  
  ...
  
  &lt;form method="post" action="{% url 'django.contrib.auth.views.login' %}"&gt;
  {% csrf_token %}
  &lt;span class="heading"&gt;{{ form.username.label_tag }}&lt;/span&gt;&lt;br/&gt;
  {{ form.username }}&lt;br/&gt;
  &lt;span class="heading"&gt;{{ form.password.label_tag }}&lt;/span&gt;&lt;br/&gt;
  {{ form.password }}&lt;br/&gt;
  &lt;div id="login-button"&gt;
  &lt;input type="submit" value="Log In" /&gt;
  &lt;input type="hidden" name="next" value="{{ next }}" /&gt;
  &lt;/div&gt;          
  &lt;/form&gt;
  
  ...
  </code></pre>
  
  <p><em>settings.py:</em></p>
  
  <pre><code>...
  
  LOGIN_URL = '/login/'
  
  ...
  </code></pre>
  
  <p><em>urls.py</em></p>
  
  <pre><code>...
  
  urlpatterns = patterns('',
      url(r'^$', 'portal.views.home', name='home'),
      url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
      url(r'^logout/$', 'django.contrib.auth.views.logout'),
  
      ...
  
  )
  </code></pre>
  
  <p>Any advice is much appreciated!</p>