forms.py:
class ImportExcelForm(Form):
file = forms.FileField(attrs={'class':'rounded_list',})
I'm trying to add css class to my filefield
in forms.I am getting this error "__init__() got an unexpected keyword argument 'attrs'"
What did I do wrong?
Thanks.
Even though the solution posted by @Daniel Roseman is also the one recommended in Django docs, it still didn't work for me. What worked for me is the following:
class ImportExcelForm(Form):
file = forms.FileField()
file.widget.attrs.update({'class': 'rounded_list'})
attrs
is not an argument to the field, it's an argument to the widget.
file = forms.FileField(widget=forms.FileInput(attrs={'class': 'rounded_list'}))
Note that some browsers don't allow styling of the file input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With