views:

145

answers:

1

I have a django site using the basic django registration framework. I have my login page working fine, but I want to change the css class on the inputs. The form passed to the login page looks to be an AuthenticationForm class.

What would be a good way to add a css class to the username, and password fields?

A: 

I do what you want like this:

def login(request):
    form = AuthenticationForm(request)
    form.fields['username'].widget.attrs['class'] = "custom_css"
    form.fields['password'].widget.attrs['style'] = "background:red"
    return render_to_response("login.html", {'form':form},
                          context_instance=RequestContext(request))
panchicore