如何覆盖Django AuthenticationForm输入CSS类? [英] How can I override the django AuthenticationForm input css class?
本文介绍了如何覆盖Django AuthenticationForm输入CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用基本django注册框架的django网站.我的登录页面工作正常,但我想更改输入中的CSS类.传递到登录页面的表单看起来是AuthenticationForm类.
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.
将css类添加到用户名和密码字段的好方法是什么?
What would be a good way to add a css class to the username, and password fields?
推荐答案
我要做这样的事情:
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))
这篇关于如何覆盖Django AuthenticationForm输入CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文