__init__() got an unexpected keyword argument 'attrs'

风流意气都作罢 提交于 2019-12-07 07:25:25

问题


forms.py

class ImportExcelForm(Form):
    file  = forms.FileField(attrs={'class':'rounded_list',})

I am trying to add css class to my filefield in forms.I am getting this error "__init__() got an unexpected keyword argument 'attrs'"

What i did wrong.

Thanks


回答1:


attrs is not an argument to the field, it's an argument to the widget.

file = forms.FieldField(widget=forms.FileInput(attrs={'class': 'rounded_list'}))

Note that some browsers don't allow styling of the file input.



来源:https://stackoverflow.com/questions/16482432/init-got-an-unexpected-keyword-argument-attrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!